File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
tagstudio/src/core/library/alchemy Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -726,7 +726,7 @@ def add_entry_field_type(
726
726
if value :
727
727
assert isinstance (value , list )
728
728
for tag in value :
729
- field_model .tags .add (Tag (name = tag ))
729
+ field_model .tags .add (self . get_tag_by_name ( tag ) or Tag (name = tag ))
730
730
731
731
elif field .type == FieldTypeEnum .DATETIME :
732
732
field_model = DatetimeField (
@@ -870,6 +870,15 @@ def get_tag(self, tag_id: int) -> Tag:
870
870
871
871
return tag
872
872
873
+ def get_tag_by_name (self , tag_name : str ) -> Tag | None :
874
+ with Session (self .engine ) as session :
875
+ statement = (
876
+ select (Tag )
877
+ .outerjoin (TagAlias )
878
+ .where (or_ (Tag .name == tag_name , TagAlias .name == tag_name ))
879
+ )
880
+ return session .scalar (statement )
881
+
873
882
def get_alias (self , tag_id : int , alias_id : int ) -> TagAlias :
874
883
with Session (self .engine ) as session :
875
884
alias_query = select (TagAlias ).where (TagAlias .id == alias_id , TagAlias .tag_id == tag_id )
You can’t perform that action at this time.
0 commit comments