我有Territory
habtm
User
和School
:
public $hasAndBelongsToMany = array(
'School' => array(
'className' => 'School',
'joinTable' => 'schools_territories',
'foreignKey' => 'territory_id',
'associationForeignKey' => 'school_id',
'order' => 'School.name',
),
'User' => array(
'className' => 'User',
'joinTable' => 'territories_users',
'foreignKey' => 'territory_id',
'associationForeignKey' => 'user_id',
'order' => array( 'User.last_name', 'User.first_name' ),
),
);
当我添加Territory
时,表单会收集School
数据,并根据当前经过身份验证的用户设置User
数据。但是,对$this->Territory->saveAll( $this->data )
的调用会保存Territory
和School
数据,但不会保存User
关联。
这是我知道我做过一些非常非常愚蠢的事情的时刻之一,但却无法看到它。以下是保存前数据的样子:
Array
(
[Territory] => Array
(
[id] =>
[advisor_first_name] => Oompa
[advisor_last_name] => Loompa
[usrp_number] => 3908
[school_search] => sylv
)
[School] => Array
(
[School] => Array
(
[0] => 4ee0bbde-3714-419d-88a5-6d78147402e8
[1] => 4ee0bbde-33d8-49ce-8e71-6d78147402e8
[2] => 4ee0bbde-e190-4894-a522-6d78147402e8
[3] => 4ee0bbde-7734-47ef-a2c0-6d78147402e8
[4] => 4ee0bbde-be54-4087-8437-6d78147402e8
[5] => 4ee0bbde-de00-473e-b6ae-6d78147402e8
[6] => 4ee0bbde-7fc0-4683-a957-6d78147402e8
[7] => 4ee0bbde-0434-4b78-9295-6d78147402e8
[8] => 4ee0bbde-defc-43cb-8c8e-6d78147402e8
[9] => 4ee0bbde-de18-45da-8e23-6d78147402e8
[10] => 4ee0bbde-fff8-4fc0-bcd7-6d78147402e8
[11] => 4ee0bbde-e1c8-42f5-9663-6d78147402e8
)
)
[User] => Array
(
[User] => Array
(
[0] => e71fcad2-2a71-11e1-837a-66730eed7998
)
)
)
或许有一个有趣的注意事项是,当我从$this->Territory
转储TerritoriesController
时,我看到School
属性(当然包含School
模型定义) ,但没有User
属性。另一方面,两个模型都在hasAndBelongsToMany
属性数组中正确表示。
如果有人能看到我失踪的东西,我将永远感激不尽。认真。我的眼睛因为看起来和哭泣的结合而流血。
感谢。