Not a problem, glad that worked for you.
On Monday, 29 February 2016 16:31:11 UTC+2, Paulo Terra wrote:
-- For future reference, you can usually get nearly instant help on the IRC channel (http://webchat.freenode.net/?channels=cakephp&uio=MT1mYWxzZSY5PXRydWUmMTE9MjQ2b8), depending on who is online of course. Stackoverflow is also usually more active than the group.
On Monday, 29 February 2016 16:31:11 UTC+2, Paulo Terra wrote:
Great! It Works! Thank you Dakota!2016-02-29 11:15 GMT-03:00 Dakota <walth...@gmail.com>:Hi Paulo,Your form field for address zipcode field is in the wrong format. http://book.cakephp.org/3.0/en/views/helpers/form. shows the correct format for each type of relation. Basically, instead of doinghtml#creating-inputs-for- associated-data
$this->Form->input('address.zipcode' );
You need to do instead do:
$this->Form->input('addresses.0.zipcode' );For hasMany relations, the key is always plural and you need to specify a numeric index.
On Sunday, 28 February 2016 22:07:32 UTC+2, Paulo Terra wrote: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:And "cpf" is also a "not null" field, whitch is properly verifyed in cake when I save.
- Model(array)
- 0APP/Model/Table/UsersTable.
php - 1APP/Model/Entity/User.php
- 2APP/Model/Table/SurveysTable.
php - 3APP/Model/Table/BuyersTable.
php - 4APP/Model/Entity/Buyer.php
- 5APP/Model/Entity/Survey.php
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)
- 0APP/Model/Table/UsersTable.
php - 1APP/Model/Entity/User.php
- 2APP/Model/Table/SurveysTable.
php - 3APP/Model/Table/BuyersTable.
php - 4APP/Model/Entity/Buyer.php
- 5APP/Model/Table/
AddressesTable.php - 6APP/Model/Entity/Address.php
- 7APP/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 a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/M8MwE8p8SZc/ .unsubscribe
To unsubscribe from this group and all its topics, send an email to cake-php+u...@googlegroups.com .
For more options, visit https://groups.google.com/d/optout .
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment