我有一种情况,由于外部原因,我必须直接保存合并记录,而不是作为合并的一部分保存记录。
- I have a
Firm
model whose data is pulled from an external source. - I have a
County
model in my app database - I have a
counties_firms
join table that I use to associate those external firms to counties.
由于生活所在,我不编辑 Firm
模型,我也不编辑 County
模型。我其实只是编辑协会。我有 Firm
模型,可以包罗我需要与公司数据有关的一切,其中一种方法是 Firm:saveCounty($data)
。它:
- Accepts incoming data that includes the firm id and the county ids that should be associated.
- Deletes all existing join records for that county
- Attempts to save all of the new join records.
我发现只有最后的县级记录被保存了
Array
(
[0] => Array
(
[firm_id] => 13
[county_id] => 4fa16e24-a25c-4523-8a9e-7d1d147402e8
)
[1] => Array
(
[firm_id] => 13
[county_id] => 4fa16e27-ccd0-4f22-97da-7d1d147402e8
)
[2] => Array
(
[firm_id] => 13
[county_id] => 4fa16e4a-68f8-4fb1-95bb-7d1d147402e8
)
)
鉴于上述数据,我将在 Firm
和 CountysFirm
之间建立实时联系,并尝试 $this-gt;CountysFirm-gt;saveall($data)
。
正如我提到的那样,在这个例子中,只有3个县协会中的最后一家得到拯救。 知道我会错过什么吗?
谢谢