0

我已经查看了我能找到的关于这个主题的所有线程,但没有解决我的问题。

我有一个 'customers' 表和一个 'employees' 表,它们应该通过 'customers_employees' 表连接。

在我的表格中,我可以选择员工,但是当我想保存数据时,他只保存“创建”和“修改”条目,而不是键。

员工有一个字符串 id,它是 CHAR(36)。

这是我在“员工”模型中的条目:

public $hasAndBelongsToMany = array(
    'Customer' => array(
        'className' => 'Customer',
        'joinTable' => 'customers_employees',
        'foreignKey' => 'employee_id',
        'associationForeignKey' => 'customer_id',
        'unique' => 'keepExisting',
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    )
);

这是我在“客户”模型中的条目:

public $hasAndBelongsToMany = array(
    'Employee' => array(
        'className' => 'Employee',
        'joinTable' => 'customers_employees',
        'foreignKey' => 'customer_id',
        'associationForeignKey' => 'employee_id',
        'unique' => 'keepExisting',
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    )
);

请求数组如下所示:

Array
(
    [Customer] => Array
        (
            [id] => 10000
            [name] => XXXXX
            [name2] => XXXXX
            [address] => XXXXX
            [address2] => 
            [country_code] => 
            [plz] => 12345
            [place] => XXXXX
            [tel] => XXXXX
            [fax] => XXXX
            [mail] => XXXXX
            [customer_price_group] => XX
            [allow_discount_line] => XX
            [payment_code] => 0
            [terms_of_delivery_id] => XXX
            [closed] =>  
            [uSt_IdNr] => DEXXXXXXXXX
            [information] => 
            [conditions] => XX
        )

    [Employee] => Array
    (
        [Employee] => Array
            (
                [0] => EMPXXX
            )

    )

)

这里是对 customers_employees 的 INSERT 查询:

INSERT INTO `appsbf_db6`.`customers_employees` (`modified`, `created`) VALUES    ('2012-07-26 06:40:22', '2012-07-26 06:40:22')

我的错误在哪里?

谢谢帮助!

4

1 回答 1

0

请求数组中的员工数据应如下所示:

[Employee] => Array
(
    [0] => Array
        (
            [Employee] => Array
                        (
                          [first_name] = ADSF
                          .........
                          ......... 
                        )
        )

    [1] => Array
        (
            [Employee] => Array
                        (
                          [first_name] = wersdf
                          .........
                          ......... 
                        )
        )

)

在您的视图中,使用以下表单元素:

 $this->Form->input('Employee.0.FirstName', array(...........

希望它对你有用。

于 2012-07-26T08:49:57.543 回答