Hi,

I have 3 tables: User, Buyer and Address:

User hasMany Address
User hasOne Buyer
Address belongsTo User
Buyer belongsTo User

In the User form (Users/add.ctp):

echo $this->Form->input('name',['label' => __('Nome')]);
echo $this->Form->input('buyer.cpf',['label' => __('CPF')]);
echo $this->Form->input('address.zipcode');



UsersTable.php:

        $this->hasMany('Addresses', [
            'foreignKey' => 'user_id'
        ]);
        
        $this->hasOne('Buyers', [
            'foreignKey' => 'user_id'
        ]);



BuyersTable.php:

        $this->table('buyers');
        $this->displayField('id');
        $this->primaryKey('id');
        $this->belongsTo('Users', [
            'foreignKey' => 'user_id',
            'joinType' => 'INNER'
        ]);


AddressTable.php:

        $this->table('addresses');
        $this->displayField('id');
        $this->primaryKey('id');
        $this->belongsTo('Users', [
            'foreignKey' => 'user_id',
            'joinType' => 'INNER'
        ]);



The field "cpf" from Buyer is recognized by cake as it´s Model is shown in 
the include path:


   - *Model*(array)
      - *0*APP/Model/Table/UsersTable.php
      - *1*APP/Model/Entity/User.php
      - *2*APP/Model/Table/SurveysTable.php
      - *3*APP/Model/Table/BuyersTable.php
      - *4*APP/Model/Entity/Buyer.php
      - *5*APP/Model/Entity/Survey.php
   
And "cpf" is also a "not null" field, whitch is properly verifyed in cake 
when I save.

The problem is the "zipcode" field in "Address". It´s is also a required 
field but it is not validated from cake. And, as can be seen, it is not 
loaded in Model list.

But when I change the relation Address relation from "hasMany" to "hasOne" 
it works (it also validade required field when I save).


UsersTable.php:

        $this->hasOne('Addresses', [
            'foreignKey' => 'user_id'
        ]);
        
        $this->hasOne('Buyers', [
            'foreignKey' => 'user_id'
        ]);



   - *Model*(array)
      - *0*APP/Model/Table/UsersTable.php
      - *1*APP/Model/Entity/User.php
      - *2*APP/Model/Table/SurveysTable.php
      - *3*APP/Model/Table/BuyersTable.php
      - *4*APP/Model/Entity/Buyer.php
      - *5*APP/Model/Table/AddressesTable.php
      - *6*APP/Model/Entity/Address.php
      - *7*APP/Model/Entity/Survey.php
   


Does anyone has a clue about what is happening?

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to