cakePHP HABTM不保存 [英] cakePHP HABTM don't save

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

问题描述



我有一个'customers'表和一个'employees'表,我已经查看了有关此主题的所有主题,但没有解决我的问题。



在我的表格中,我可以选择员工,但是当我想保存数据时,他只保存'created'



该员工的字符串ID为CHAR(36)。



这是我在员工模式中的条目:

  public $ hasAndBelongsToMany = array '=> 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'=& =>''

);

请求数组如下所示:

  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')

我的错误在哪里?



Thx帮助!

方案

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

  [Employee] => Array 

[0] => Array

[Employee] => Array

[first_name] = ADSF
.........
.........



[1] => Array

[Employee] => Array

[first_name] = wersdf
.........
..... ....




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

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

希望它能工作为您。


I have looked into all threads I could find about this Topic, but nothing solves my Problem.

I have a 'customers' table and an 'employees' table which should be connected via the 'customers_employees' table.

In my Form I can select the employees, but when I want to save the data he only save the 'created' and 'modified' entry and not the keys.

The employee has an string id which is CHAR(36).

This is my entry in the 'employee' model:

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' => ''
    )
);

This is my entry in the 'customer' model:

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' => ''
    )
);

The request array looks like this:

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
            )

    )

)

Here the INSERT query to customers_employees:

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

Where is my mistake?

Thx for help!

解决方案

Your Employee data in request array should looks like:

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

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

)

In your view use the form elements like:

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

Hope it will work for you.

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

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