fluent-kit
fluent-kit copied to clipboard
Relation property assignment
Currently, model properties that use the Sibling, Children, or Parent properties wrappers (and others), do not support having their values set and then automagically handling the extra inserts/updates into the database. This is a feature we would like to support in the future.
-
@Parentand@OptionalParent: When you set the value and then create or update that property's model in the database, we should also check to see if the parent model exists. If it doesn't, we should insert it. This can easily be done by calling anINSERT ON CONFLICt IGNOREquery on the parent model (if you are using a SQL database). -
@Siblings: When creating or updating the model with a siblings property, we should insert new sibling models into its table if there are no matches where the model ID and sibling ID match. This can easily be checked because the@Siblingsproperty wrapper has access to the pivot table and the key paths to the two properties that are the foreign IDs. If we want to be smart we will also delete any pivot rows that have the current model's ID but not any of the attached sibling IDs. -
@Children: The implementation for this would act differently based on the type of the parent property wrapper that it connects through. If the child uses an@Parentproperty wrapper, the child will have to be deleted from the database, since a value is required in the parent column. If both the parent and child models are soft-deletable, then the child model could be soft-deleted and the parent column would still have the ID of the parent that it is no longer connected to. If the child uses an@OptionalParentproperty wrapper, then the parent column would simply bet set tonil.