CakePHP saveAll保存一个HABTM,但不保存另一个HABTM

时间:2012-01-13 16:20:17

标签: cakephp cakephp-1.3

我有Territory habtm UserSchool

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 )的调用会保存TerritorySchool数据,但不会保存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属性数组中正确表示。

如果有人能看到我失踪的东西,我将永远感激不尽。认真。我的眼睛因为看起来和哭泣的结合而流血。

感谢。

0 个答案:

没有答案