How to configure saving strategy (append) for belongsToMany Association?

梦想与她 提交于 2019-12-12 04:22:41

问题


i have a belongsToMany association which deletes joinTable data because i just put new connections inside the entity to be persited.
So i read here about the 2 strategys: append and replace. Replace is the default one. But i could not find out yet how to set it to append strategy?


回答1:


You can define belongsToMany relation with saveStrategy keyword which accept either append or replace. So code should be like

$this->belongsToMany('Articles', [
            'joinTable' => 'articles_tags',
            'saveStrategy' => 'append'
        ]);

For more check official Doc



来源:https://stackoverflow.com/questions/41428439/how-to-configure-saving-strategy-append-for-belongstomany-association

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!