If I have a many-to-many relationship it's super easy to update the relationship with its sync
method.
但我会用什么来同步一对多的关系呢?
- table
posts
:id, name
- 表
links
:id, name, post_id
Here, each Post
can have multiple Link
s.
I'd like to synchronize the links associated with a specific post in the database, against an inputted collection of links (for example, from a CRUD form where I can add, remove, and modify links).
应该删除数据库中输入集合中不存在的链接.数据库和我的输入中存在的链接应更新以反映输入,仅存在于我的输入中的链接应作为数据库中的新记录添加.
To summarize the desired behavior:
- inputArray=true/db=false--创建
- inputArray = false / db = true ---DELETE
- inputArray=true/db=true-更新