Forráskód Böngészése

Fix to triggers not existing

Kenric Nugteren 7 hónapja
szülő
commit
a75dc1d39c

+ 1 - 1
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -345,7 +345,7 @@ namespace InABox.Core
         /// <returns></returns>
         public static IEnumerable<IProperty> LocalProperties(Type type)
             => PropertiesInternal(type).Where(
-                x => (!x.HasParentEntityLink() || (x.Parent?.HasParentEntityLink() != true && x.Name.EndsWith(".ID")))
+                x => !x.IsParent && (!x.HasParentEntityLink() || (x.Parent?.HasParentEntityLink() != true && x.Name.EndsWith(".ID")))
                     && !x.IsCalculated);
 
         /// <summary>

+ 7 - 8
inabox.database.sqlite/SQLiteProvider.cs

@@ -691,21 +691,20 @@ public class SQLiteProviderFactory : IProviderFactory
             var setNullFields = new List<string>();
             var cascadeFields = new List<string>();
 
-            var props = DatabaseSchema.RootProperties(otherType)
-                .Where(x => x.IsEntityLink
-                            && x.PropertyType.GetInterfaceDefinition(typeof(IEntityLink<>))?.GenericTypeArguments[0] == type
+            var props = DatabaseSchema.LocalProperties(otherType)
+                .Where(x => x.Parent?.IsEntityLink == true
+                            && x.Parent.PropertyType.GetInterfaceDefinition(typeof(IEntityLink<>))?.GenericTypeArguments[0] == type
                             && !x.IsCalculated);
             foreach(var prop in props)
             {
-                var fieldname = $"{prop.Name}.ID";
-                if(prop.GetAttribute<EntityRelationshipAttribute>() is EntityRelationshipAttribute attr
+                if(prop.Parent?.GetAttribute<EntityRelationshipAttribute>() is EntityRelationshipAttribute attr
                     && attr.Action == DeleteAction.Cascade)
                 {
-                    cascadeFields.Add(fieldname);
+                    cascadeFields.Add(prop.Name);
                 }
                 else
                 {
-                    setNullFields.Add(fieldname);
+                    setNullFields.Add(prop.Name);
                 }
             }
             cascadeFields.Sort();
@@ -715,7 +714,7 @@ public class SQLiteProviderFactory : IProviderFactory
             {
                 cascades.Add(new(otherType, cascadeFields));
             }
-            if(setNulls.Count > 0)
+            if(setNullFields.Count > 0)
             {
                 setNulls.Add(new(otherType, setNullFields));
             }