Hello Lorenzo,
please Ignore Previous debug($unit) & find the latest debug($unit) before
all save()
*/src/Controller/UnitsController.php* (line *59*)
object(Cake\ORM\Entity) {
'new' => true,
'accessible' => [
'*' => true
],
'properties' => [
'cost' => object(Cake\ORM\Entity) {
'new' => true,
'accessible' => [
'*' => true
],
'properties' => [
'rental_cost' => (float) 14500,
'unit_id' => (int) 1
],
'dirty' => [
'rental_cost' => true,
'unit_id' => true
],
'original' => [],
'virtual' => [],
'errors' => [],
'repository' => 'Costs'
},
'fixed_cost' => object(Cake\ORM\Entity) {
'new' => true,
'accessible' => [
'*' => true
],
'properties' => [
'gas_bill' => (int) 450,
'water_bill' => (int) 600,
'service_bill' => (int) 500,
'unit_id' => (int) 1
],
'dirty' => [
'gas_bill' => true,
'water_bill' => true,
'service_bill' => true,
'unit_id' => true
],
'original' => [],
'virtual' => [],
'errors' => [],
'repository' => 'FixedCosts'
}
],
'dirty' => [
'cost' => true,
'fixed_cost' => true
],
'original' => [],
'virtual' => [],
'errors' => [],
'repository' => 'Units'
}
Note: A new record is being saved in UnitsTable but i don't want to
Thanks
Bayezid
On Fri, Dec 12, 2014 at 10:35 PM, Md Bayezid Alam <[email protected]>
wrote:
>
> Hello Lerenzo,
>
> Please find the UnitsTable and debug($unit) as follows:
>
> *UnitsTable:*
>
> <?php
> namespace App\Model\Table;
>
> use Cake\ORM\Table;
>
> class UnitsTable extends Table {
>
> public function initialize(array $config) {
> $this->table('units');
> $this->addBehavior('Timestamp');
> $this->primaryKey('id');
>
> // association goes here
> $this->belongsTo('Houses',[
> 'foreignKey' => 'house_id'
> ]);
>
> $this->hasOne('Costs',[
> 'foreignKey' => 'unit_id'
> ]);
>
> $this->hasOne('FixedCosts',[
> 'foreignKey' => 'unit_id'
> ]);
>
> }
> }
>
> ?>
>
> *debug($unit):*
>
> */src/Controller/UnitsController.php* (line *53*)
>
> object(Cake\ORM\Entity) {
>
> 'new' => true,
> 'accessible' => [
> '*' => true
> ],
> 'properties' => [
> 'cost' => object(Cake\ORM\Entity) {
>
> 'new' => true,
> 'accessible' => [
> '*' => true
> ],
> 'properties' => [
> 'rental_cost' => (float) 14500
> ],
> 'dirty' => [
> 'rental_cost' => true
> ],
> 'original' => [],
> 'virtual' => [],
> 'errors' => [],
> 'repository' => 'Costs'
>
> },
> 'fixed_cost' => object(Cake\ORM\Entity) {
>
> 'new' => true,
> 'accessible' => [
> '*' => true
> ],
> 'properties' => [
> 'gas_bill' => (int) 450,
> 'water_bill' => (int) 600,
> 'service_bill' => (int) 500
> ],
> 'dirty' => [
> 'gas_bill' => true,
> 'water_bill' => true,
> 'service_bill' => true
> ],
> 'original' => [],
> 'virtual' => [],
> 'errors' => [],
> 'repository' => 'FixedCosts'
>
> }
> ],
> 'dirty' => [
> 'cost' => true,
> 'fixed_cost' => true
> ],
> 'original' => [],
> 'virtual' => [],
> 'errors' => [],
> 'repository' => 'Units'
>
> }
>
>
> Thanks
> Bayezid
>
> On Fri, Dec 12, 2014 at 3:02 PM, José Lorenzo <[email protected]> wrote:
>>
>> Can you show how your UnitsTable look like? Can you also show a
>> debug($unit) before you all save() ?
>>
>>
>> On Thursday, December 11, 2014 5:08:27 PM UTC+1, Bayezid Alam wrote:
>>>
>>> Hi,
>>>
>>>
>>> i have Tables :
>>>
>>> Units hasOne costs & hasOne fixed_costs
>>>
>>> i want to add data to costs and fixed_costs table using units's primary
>>> key from units Controller.
>>>
>>> i did below things but its creating a new record at unit Table instead
>>> of using primaryKey
>>>
>>> Form at unitsController:
>>>
>>> <?php
>>>
>>> echo $this->Form->create($unit);
>>> echo $this->Form->input('cost.rental_cost');
>>> echo $this->Form->input('fixed_cost.gas_bill');
>>> echo $this->Form->input('fixed_cost.water_bill');
>>> echo $this->Form->input('fixed_cost.service_bill');
>>> echo $this->Form->button('Save Costs');
>>> echo $this->Form->end();
>>>
>>> ?>
>>>
>>> Function at UnitsController:
>>>
>>> public function add_cost($uId){
>>> if (!$uId){
>>> throw new NotFoundException(__('Unit id Not found, try with
>>> a valid ID'));
>>> }
>>>
>>> $unitId = $this->Units->get($uId);
>>>
>>> $unit = $this->Units->newEntity($this->request->data(),['associated'
>>> => ['Costs', 'FixedCosts']]);
>>>
>>> if ($this->request->is('post')){
>>> $unit->cost->unit_id = $unit->fixed_cost->unit_id =
>>> $unitId->id;
>>> if ($this->Units->save($unit)){
>>> $this->Flash->success(__('The unit cost has been
>>> added'));
>>> return $this->redirect(['controller' => 'houses',
>>> 'action' => 'view', $unit->house_id]);
>>> }
>>> }
>>>
>>> $this->set(compact('unit'));
>>> }
>>>
>>> Please suggest me on this regard.
>>>
>>> Thanks
>>> Bayezid
>>>
>>> --
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/cake-php.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.