如何为belongsToMany协会配置保存策略(追加)? [英] How to configure saving strategy (append) for belongsToMany Association?

查看:96
本文介绍了如何为belongsToMany协会配置保存策略(追加)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个belongsToMany关联,该关联删除了joinTable数据,因为我只是将新的连接放在要持久化的实体内。

所以我读了此处介绍以下两种策略:附加和替换。
替换是默认值。但是我还找不到如何将其设置为追加策略的方法?

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?

推荐答案

您可以使用<$ c $定义belongsToMany关系c> saveStrategy 关键字,可以接受追加或替换。因此代码应类似于

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

这篇关于如何为belongsToMany协会配置保存策略(追加)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆