CakePHP HABTM我想保存重复 [英] CakePHP HABTM I want duplicates at save

查看:192
本文介绍了CakePHP HABTM我想保存重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备一些HABTM,用 unique 键(例如 true false

I prepare some HABTM, works fine with unique key (like true, false, keepExisting).

但是,我想在一个保存方法中使用重复项,如下:

But, I would like using duplicates in one saving method, like this:

$this->request->data['Model']['Model'] = array(7,7,7,7,7,8,10,7);

但是上面的代码只保存 array(7,8,10) code>。

But code above save only array(7,8,10).

unique 不适用于此。对我的情况有一些解决方案?

Key unique is not for this. There is some solution for my situation?

推荐答案

我知道这一个是旧的,但解决方案是使用连接表您的HABTM关系。

I know this one is old but the solution is using a Model on the Join table of your HABTM relationship.

我得到了答案尝试保存重复的关联在CakePHP HABTM关系保存

正如我在注释中提到的,你的键控将需要稍微改变以处理HasMany关联,如:

As I mentioned in the notes your keying will need to change slightly to handle the HasMany association such as:

data[JoinTableModelAlias][][id_field_name]

这篇关于CakePHP HABTM我想保存重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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