Re: Another saveAll() problem

2010-02-23 Thread Nico
Not bad for a first post ;)

I seem to remember reading about that problem the other day, so it was
fresh in my mind. Glad it helped.

On Feb 23, 7:04 pm, WebbedIT  wrote:
> How the heck did Nico know you had a beforeSave() method created in
> the model?  Wow, he's a mentalist, wonder if he'll give me next week's
> Lottery numbers?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Another saveAll() problem

2010-02-23 Thread WebbedIT
How the heck did Nico know you had a beforeSave() method created in
the model?  Wow, he's a mentalist, wonder if he'll give me next week's
Lottery numbers?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Another saveAll() problem

2010-02-23 Thread Lucca Mordente
Both the data and associations are correct.

My mistake was on what Nico said.
I've just forgot to return true inside beforeSave() method!

Thank you all guys!


On 23 fev, 03:30, Nico  wrote:
> Another thing to check is the beforeSave() method to make sure that
> returns true. Are any of your other saves to the database working?
>
> On Feb 23, 7:48 am, Jeremy Burns  wrote:
>
>
>
> > Have you checked to see if your data array is missing any required fields? 
> > If so, it would still pass validation but fail at the database level. Also, 
> > is your validation right (does it match what the database expects)?
>
> > Jeremy Burns
> > jeremybu...@me.com
>
> > On 22 Feb 2010, at 21:06, Lucca Mordente wrote:
>
> > > Hi there.
>
> > > I'm having problems saving a model and it's related data.
> > > a $this->Paper->saveAll($this->data); call returns false.
>
> > > and later I figured out that a simple $this->Paper->Document-
> > >> save($this->data) is failing too.
>
> > > the data is set correctly and there are no validationErrors.
>
> > > any suggestion?
> > > Thanks!
> > > Lucca
>
> > > the associations follow:
>
> > > Paper hasMany Chart
> > > Paper hasMany Table
> > > Paper hasMany Document
>
> > > PaperAttachment belongsTo Paper
>
> > > and the code:
>
> > > class Paper extends AppModel {
> > >    var $hasOne = array(
> > >        'Chart' => array(
> > >            'className'=>'PaperAttachment'
> > >        ),
> > >        'Table' => array(
> > >            'className'=>'PaperAttachment'
> > >        ),
> > >        'Document' => array(
> > >            'className'=>'PaperAttachment'
> > >        ),
> > >    );
> > > }
>
> > > class PaperAttachment extends AppModel {
> > >    var $belongsTo = array(
> > >        'Paper' => array(
> > >        )
> > >    );
> > > }
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
> > > with their CakePHP related questions.
>
> > > You received this message because you are subscribed to the Google Groups 
> > > "CakePHP" group.
> > > To post to this group, send email to cake-php@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Another saveAll() problem

2010-02-23 Thread Nico
Another thing to check is the beforeSave() method to make sure that
returns true. Are any of your other saves to the database working?

On Feb 23, 7:48 am, Jeremy Burns  wrote:
> Have you checked to see if your data array is missing any required fields? If 
> so, it would still pass validation but fail at the database level. Also, is 
> your validation right (does it match what the database expects)?
>
> Jeremy Burns
> jeremybu...@me.com
>
> On 22 Feb 2010, at 21:06, Lucca Mordente wrote:
>
> > Hi there.
>
> > I'm having problems saving a model and it's related data.
> > a $this->Paper->saveAll($this->data); call returns false.
>
> > and later I figured out that a simple $this->Paper->Document-
> >> save($this->data) is failing too.
>
> > the data is set correctly and there are no validationErrors.
>
> > any suggestion?
> > Thanks!
> > Lucca
>
> > the associations follow:
>
> > Paper hasMany Chart
> > Paper hasMany Table
> > Paper hasMany Document
>
> > PaperAttachment belongsTo Paper
>
> > and the code:
>
> > class Paper extends AppModel {
> >    var $hasOne = array(
> >        'Chart' => array(
> >            'className'=>'PaperAttachment'
> >        ),
> >        'Table' => array(
> >            'className'=>'PaperAttachment'
> >        ),
> >        'Document' => array(
> >            'className'=>'PaperAttachment'
> >        ),
> >    );
> > }
>
> > class PaperAttachment extends AppModel {
> >    var $belongsTo = array(
> >        'Paper' => array(
> >        )
> >    );
> > }
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups 
> > "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Another saveAll() problem

2010-02-23 Thread WebbedIT
You state that

> the associations follow:
>
> Paper hasMany Chart
> Paper hasMany Table
> Paper hasMany Document

Yet your model defines hasOne associations, and all associate to the
same model without any info on their foreign key, conditions etc? You
need to clarify your associations are correct before you attempt to
start saving data.

> class Paper extends AppModel {
>         var $hasOne = array(
>             'Chart' => array(
>                 'className'=>'PaperAttachment'
>             ),
>             'Table' => array(
>                 'className'=>'PaperAttachment'
>             ),
>             'Document' => array(
>                 'className'=>'PaperAttachment'
>             ),
>         );
>
> }

Make sure your debug level is set to 1 or higher and add echo
debug($this->data); into your controller before the save command so
you can copy and paste the structure of your data array.  When saving
hasMany data your array needs to be in a specific format to tell Cake
to save multiple rows.

HTH

Paul.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Another saveAll() problem

2010-02-22 Thread Jeremy Burns
Have you checked to see if your data array is missing any required fields? If 
so, it would still pass validation but fail at the database level. Also, is 
your validation right (does it match what the database expects)?

Jeremy Burns
jeremybu...@me.com

On 22 Feb 2010, at 21:06, Lucca Mordente wrote:

> Hi there.
> 
> I'm having problems saving a model and it's related data.
> a $this->Paper->saveAll($this->data); call returns false.
> 
> and later I figured out that a simple $this->Paper->Document-
>> save($this->data) is failing too.
> 
> the data is set correctly and there are no validationErrors.
> 
> any suggestion?
> Thanks!
> Lucca
> 
> the associations follow:
> 
> Paper hasMany Chart
> Paper hasMany Table
> Paper hasMany Document
> 
> PaperAttachment belongsTo Paper
> 
> and the code:
> 
> class Paper extends AppModel {
>   var $hasOne = array(
>   'Chart' => array(
>   'className'=>'PaperAttachment'
>   ),
>   'Table' => array(
>   'className'=>'PaperAttachment'
>   ),
>   'Document' => array(
>   'className'=>'PaperAttachment'
>   ),
>   );
> }
> 
> class PaperAttachment extends AppModel {
>var $belongsTo = array(
>'Paper' => array(
>)
>);
> }
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Another saveAll() problem

2010-02-22 Thread Lucca Mordente
Hi there.

I'm having problems saving a model and it's related data.
a $this->Paper->saveAll($this->data); call returns false.

and later I figured out that a simple $this->Paper->Document-
>save($this->data) is failing too.

the data is set correctly and there are no validationErrors.

any suggestion?
Thanks!
Lucca

the associations follow:

Paper hasMany Chart
Paper hasMany Table
Paper hasMany Document

PaperAttachment belongsTo Paper

and the code:

class Paper extends AppModel {
var $hasOne = array(
'Chart' => array(
'className'=>'PaperAttachment'
),
'Table' => array(
'className'=>'PaperAttachment'
),
'Document' => array(
'className'=>'PaperAttachment'
),
);
}

class PaperAttachment extends AppModel {
var $belongsTo = array(
'Paper' => array(
)
);
}

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


HABT many saveAll problem with multiple child records,

2010-02-03 Thread waseem gondal
hi,
I have scenario , where i want to save a meeting,  and meeting has
relation with topic habtm,
Tables: Meeting, Topic, MeetingsTopics
Meeting HABTM with Topic


this  sample data is working fine,

[Meeting] => Array
(
[date] => 2010-02-10
[Priority] => 1
)

[Topic] => Array
(
[id] => Array
(
[0] => 6
)

)

These below data is saving properly.
But it didn't save data when i have meeting ids more than one.

[Meeting] => Array
(
[date] => 2010-02-06
[name] => "test"
[Priority] => 1
)

[Topic] => Array
(
[id] => Array
(
[0] => 7
[1] => 14
[2] => 13
)

)

I am using saveAll($this->data) function to save that.

and how can i hand the scenario when i have to add new topic at
meetings view and automatically relate this current meeting

[Meeting] => Array
(
[date] =>
[Priority] => 1
)

[Topic] => Array
(
[id] => Array
(
[0] => 16
)

[name] => adsfasdfasdfasdfas
)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: saveAll Problem

2009-10-16 Thread Edinei Luis Cipriani

Ok,

image hasMany property and property belongsTo image?


Em 16/10/2009, às 18:31, ilcaduceo escreveu:

>
> This is the output:
>
> Array
> (
>[Property] => Array
>(
>[title] => lorem ipsum
>[descrizione] => Lorem ipsum dolor sit amet...
>[prezzo] => 50
>[metratura] => 120
>[affitto] => 0
>[zones_id] => 2
>[types_id] => 2
>)
>
>[Image] => Array
>(
>[0] => Array
>(
>[nomeFile] => lorempisum
>)
>
>[1] => Array
>(
>[nomeFile] => loremipsum
>)
>
>)
>
> )
>
> What's wrong?
>
>
> On 16 Ott, 22:21, "Edinei L. Cipriani"  wrote:
>> Please, debug($this->data);
>>
>> 2009/10/16 ilcaduceo 
>>
>>
>>
>>
>>
>>> I have a problem with the saveAll function. There are two models,
>>> Property and Images:
>>
>>> Property HasMany Image
>>> Image belongTo Property
>>
>>> Also I have this form:
>>
>>> --
>>> 
>>
>>> create('Property', array('type' => 'file'));?>
>>>
>>>
>>>>>echo $form->input('Property.title');
>>>echo $form->input('Property.descrizione');
>>>echo $form->input('Property.prezzo');
>>>echo $form->input('Property.metratura');
>>>echo $form->input('Property.affitto');
>>>echo $form->input('Property.zones_id');
>>>echo $form->input('Property.types_id');
>>
>>>echo $form->input('Image.0.nomeFile');
>>>echo $form->input('Image.1.nomeFile');
>>>?>
>>>
>>
>>> end('Salva'); ?>
>>> 
>>
>>> ---
>>
>>> and this is the action method in my controller:
>>
>>> --
>>> function add() {
>>
>>>if (!empty($this->data)) {
>>>$this->Property->create();
>>
>>>if ($this->Property->saveAll($this->data,  
>>> array
>>> ('validate'=>'first')) {
>>>$this->Session->setFlash(__('The  
>>> Property
>>> has been saved', true));
>>>$this- 
>>> >redirect(array('action'=>'add'));
>>>} else {
>>>$this->Session->setFlash(__('The  
>>> Property
>>> could not be saved.
>>> Please, try again.', true));
>>>}
>>>}
>>>$zones = $this->Property->Zone->find('list');
>>>$types = $this->Property->Type->find('list');
>>>$this->set(compact('zones', 'types'));
>>>}
>>
>>> --
>>
>>> Now the result is that the Property model is saved but the related
>>> model Image is not saved. Why? I have checked the array sintax and  
>>> it
>>> is correct, also i've checked the Model Fields and they are correct.
>>
>>> Can someone help me? Thak you...
>>
>> --
>> Edinei L. Cipriani
>> Desenvolvedor Colégio Trilingue Inovaçãowww.colegioinovacao.com.br
>> Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
>> Integrante do grupo Fool N Lost de algoritimos computacionais
>> Fone 49 84149086
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: saveAll Problem

2009-10-16 Thread ilcaduceo

I've found an error in the model associations, thanks for give me
inspiration ;)

On 16 Ott, 23:31, ilcaduceo  wrote:
> This is the output:
>
> Array
> (
>     [Property] => Array
>         (
>             [title] => lorem ipsum
>             [descrizione] => Lorem ipsum dolor sit amet...
>             [prezzo] => 50
>             [metratura] => 120
>             [affitto] => 0
>             [zones_id] => 2
>             [types_id] => 2
>         )
>
>     [Image] => Array
>         (
>             [0] => Array
>                 (
>                     [nomeFile] => lorempisum
>                 )
>
>             [1] => Array
>                 (
>                     [nomeFile] => loremipsum
>                 )
>
>         )
>
> )
>
> What's wrong?
>
> On 16 Ott, 22:21, "Edinei L. Cipriani"  wrote:
>
> > Please, debug($this->data);
>
> > 2009/10/16 ilcaduceo 
>
> > > I have a problem with the saveAll function. There are two models,
> > > Property and Images:
>
> > > Property HasMany Image
> > > Image belongTo Property
>
> > > Also I have this form:
>
> > > --
> > > 
>
> > > create('Property', array('type' => 'file'));?>
> > >        
> > >                
> > >         > >                echo $form->input('Property.title');
> > >                echo $form->input('Property.descrizione');
> > >                echo $form->input('Property.prezzo');
> > >                echo $form->input('Property.metratura');
> > >                echo $form->input('Property.affitto');
> > >                echo $form->input('Property.zones_id');
> > >                echo $form->input('Property.types_id');
>
> > >                echo $form->input('Image.0.nomeFile');
> > >                echo $form->input('Image.1.nomeFile');
> > >        ?>
> > >        
>
> > > end('Salva'); ?>
> > > 
>
> > > ---
>
> > > and this is the action method in my controller:
>
> > > --
> > > function add() {
>
> > >                if (!empty($this->data)) {
> > >                        $this->Property->create();
>
> > >                        if ($this->Property->saveAll($this->data, array
> > > ('validate'=>'first')) {
> > >                                $this->Session->setFlash(__('The Property
> > > has been saved', true));
> > >                                $this->redirect(array('action'=>'add'));
> > >                        } else {
> > >                                $this->Session->setFlash(__('The Property
> > > could not be saved.
> > > Please, try again.', true));
> > >                        }
> > >                }
> > >                $zones = $this->Property->Zone->find('list');
> > >                $types = $this->Property->Type->find('list');
> > >                $this->set(compact('zones', 'types'));
> > >        }
>
> > > --
>
> > > Now the result is that the Property model is saved but the related
> > > model Image is not saved. Why? I have checked the array sintax and it
> > > is correct, also i've checked the Model Fields and they are correct.
>
> > > Can someone help me? Thak you...
>
> > --
> > Edinei L. Cipriani
> > Desenvolvedor Colégio Trilingue Inovaçãowww.colegioinovacao.com.br
> > Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
> > Integrante do grupo Fool N Lost de algoritimos computacionais
> > Fone 49 84149086
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: saveAll Problem

2009-10-16 Thread ilcaduceo

This is the output:

Array
(
[Property] => Array
(
[title] => lorem ipsum
[descrizione] => Lorem ipsum dolor sit amet...
[prezzo] => 50
[metratura] => 120
[affitto] => 0
[zones_id] => 2
[types_id] => 2
)

[Image] => Array
(
[0] => Array
(
[nomeFile] => lorempisum
)

[1] => Array
(
[nomeFile] => loremipsum
)

)

)

What's wrong?


On 16 Ott, 22:21, "Edinei L. Cipriani"  wrote:
> Please, debug($this->data);
>
> 2009/10/16 ilcaduceo 
>
>
>
>
>
> > I have a problem with the saveAll function. There are two models,
> > Property and Images:
>
> > Property HasMany Image
> > Image belongTo Property
>
> > Also I have this form:
>
> > --
> > 
>
> > create('Property', array('type' => 'file'));?>
> >        
> >                
> >         >                echo $form->input('Property.title');
> >                echo $form->input('Property.descrizione');
> >                echo $form->input('Property.prezzo');
> >                echo $form->input('Property.metratura');
> >                echo $form->input('Property.affitto');
> >                echo $form->input('Property.zones_id');
> >                echo $form->input('Property.types_id');
>
> >                echo $form->input('Image.0.nomeFile');
> >                echo $form->input('Image.1.nomeFile');
> >        ?>
> >        
>
> > end('Salva'); ?>
> > 
>
> > ---
>
> > and this is the action method in my controller:
>
> > --
> > function add() {
>
> >                if (!empty($this->data)) {
> >                        $this->Property->create();
>
> >                        if ($this->Property->saveAll($this->data, array
> > ('validate'=>'first')) {
> >                                $this->Session->setFlash(__('The Property
> > has been saved', true));
> >                                $this->redirect(array('action'=>'add'));
> >                        } else {
> >                                $this->Session->setFlash(__('The Property
> > could not be saved.
> > Please, try again.', true));
> >                        }
> >                }
> >                $zones = $this->Property->Zone->find('list');
> >                $types = $this->Property->Type->find('list');
> >                $this->set(compact('zones', 'types'));
> >        }
>
> > --
>
> > Now the result is that the Property model is saved but the related
> > model Image is not saved. Why? I have checked the array sintax and it
> > is correct, also i've checked the Model Fields and they are correct.
>
> > Can someone help me? Thak you...
>
> --
> Edinei L. Cipriani
> Desenvolvedor Colégio Trilingue Inovaçãowww.colegioinovacao.com.br
> Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
> Integrante do grupo Fool N Lost de algoritimos computacionais
> Fone 49 84149086
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: saveAll Problem

2009-10-16 Thread Edinei L. Cipriani
Please, debug($this->data);

2009/10/16 ilcaduceo 

>
> I have a problem with the saveAll function. There are two models,
> Property and Images:
>
> Property HasMany Image
> Image belongTo Property
>
> Also I have this form:
>
> --
> 
>
> create('Property', array('type' => 'file'));?>
>
>
>echo $form->input('Property.title');
>echo $form->input('Property.descrizione');
>echo $form->input('Property.prezzo');
>echo $form->input('Property.metratura');
>echo $form->input('Property.affitto');
>echo $form->input('Property.zones_id');
>echo $form->input('Property.types_id');
>
>echo $form->input('Image.0.nomeFile');
>echo $form->input('Image.1.nomeFile');
>?>
>
>
> end('Salva'); ?>
> 
>
> ---
>
> and this is the action method in my controller:
>
> --
> function add() {
>
>if (!empty($this->data)) {
>$this->Property->create();
>
>if ($this->Property->saveAll($this->data, array
> ('validate'=>'first')) {
>$this->Session->setFlash(__('The Property
> has been saved', true));
>$this->redirect(array('action'=>'add'));
>} else {
>$this->Session->setFlash(__('The Property
> could not be saved.
> Please, try again.', true));
>}
>}
>$zones = $this->Property->Zone->find('list');
>$types = $this->Property->Type->find('list');
>$this->set(compact('zones', 'types'));
>}
>
>
> --
>
> Now the result is that the Property model is saved but the related
> model Image is not saved. Why? I have checked the array sintax and it
> is correct, also i've checked the Model Fields and they are correct.
>
> Can someone help me? Thak you...
>
> >
>


-- 
Edinei L. Cipriani
Desenvolvedor Colégio Trilingue Inovação
www.colegioinovacao.com.br
Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
Integrante do grupo Fool N Lost de algoritimos computacionais
Fone 49 84149086

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



saveAll Problem

2009-10-16 Thread ilcaduceo

I have a problem with the saveAll function. There are two models,
Property and Images:

Property HasMany Image
Image belongTo Property

Also I have this form:
--


create('Property', array('type' => 'file'));?>


input('Property.title');
echo $form->input('Property.descrizione');
echo $form->input('Property.prezzo');
echo $form->input('Property.metratura');
echo $form->input('Property.affitto');
echo $form->input('Property.zones_id');
echo $form->input('Property.types_id');

echo $form->input('Image.0.nomeFile');
echo $form->input('Image.1.nomeFile');
?>


end('Salva'); ?>

---

and this is the action method in my controller:
--
function add() {

if (!empty($this->data)) {
$this->Property->create();

if ($this->Property->saveAll($this->data, array
('validate'=>'first')) {
$this->Session->setFlash(__('The Property has 
been saved', true));
$this->redirect(array('action'=>'add'));
} else {
$this->Session->setFlash(__('The Property could 
not be saved.
Please, try again.', true));
}
}
$zones = $this->Property->Zone->find('list');
$types = $this->Property->Type->find('list');
$this->set(compact('zones', 'types'));
}

--

Now the result is that the Property model is saved but the related
model Image is not saved. Why? I have checked the array sintax and it
is correct, also i've checked the Model Fields and they are correct.

Can someone help me? Thak you...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



SaveAll problem?

2009-07-23 Thread sijo jose
Hi all,

Well I have been stuck up for some time with this problem.

Well I have Registration page in my application. The Registration process
can be done in ways.
   1. When a new Customer comes directly for registration.
   2. When a Lead becomes a Customer.

My Registration Object has the following relation.

Registration - hasMany - EducationalDetails
   - hasMany - ProfessionalDetails
   - hasMany - EligibilityTests
   - hasMany - CandidateStudyAbroad.


When a new Customer comes for Registration the data would be empty and while
saving REGISTRATION and all its corresponding models are getting stored.
So far no issues.

But when an existing Lead is being Registered, I am sending the Lead Id
through URL, retrieving it from database and populating the Registration
form using $this->data().
The form is rendering perfect with all the values populated.
But when I am trying to save the Form, the values for the Registration
object except created ans modified are not being saved. The values for the
corresponding related object are all being saved well.

When I checked the Query that is being run I found out that in the second
condition only the created and modified values are being Inserted for
REGISTRATION object.

My Controller Function :

function studyabroadregistration($id = null){
if (array_key_exists('cancel', $this->params['form'])){
$this->Session->setFlash('Action Cancelled.',true);

$this->redirect(array('controller'=>'registrations','action'=>'index'));
}else if(array_key_exists('cancelfromlead', $this->params['form'])){
$this->Session->setFlash('Action Cancelled.',true);
$this->redirect(array('controller'=>'leads','action'=>'index'));
}else if(array_key_exists('save', $this->params['form'])){

if (!empty($this->data)) {

$this->data['Registration']['display_name']=$this->data['Registration']['first_name'].'
'.$this->data['Registration']['last_name'];
$this->data['Registration']['file_number']='IA2009';
$this->data['Registration']['service_intrested']='Study
Abroad';

$this->data['Registration']['registration_date']=$this->DateHelper->getNextDate();
$this->data['Registration']['registration_status']='NEW';
for($i=0;$idata['ProfessionalDetail']);$i++){
if($this->data['ProfessionalDetail'][$i]['start_date']
!= null)

$this->data['ProfessionalDetail'][$i]['start_date']=date("Y-m-d
H:i:s",strtotime($this->data['ProfessionalDetail'][$i]['start_date']));

$this->log($this->data['ProfessionalDetail'][$i]['start_date']);
if($this->data['ProfessionalDetail'][$i]['end_date'] !=
null)

$this->data['ProfessionalDetail'][$i]['end_date']=date("Y-m-d
H:i:s",strtotime($this->data['ProfessionalDetail'][$i]['end_date']));

$this->log($this->data['ProfessionalDetail'][$i]['end_date']);
}
debug($this->data);
if ($this->Registration->saveAll($this->data)) {
//$this->Registration->save()
if($this->data['Registration']['lead_id'] !=null){
$leadId=$this->data['Registration']['lead_id'];
$this->data = $this->Lead->read(null, $leadId);

$this->data['Lead']['registration_id']=$this->Registration->getLastInsertId();
$this->data['Lead']['status']='Completed';
$this->Lead->save($this->data['Lead']);
}
$this->Session->setFlash(__('The Registration has
ergqwerg been saved', true));

//$this->redirect(array('controller'=>'registrations','action'=>'registrationlist'));
}else{
$this->Session->setFlash(__('The Registration could not
be saved. Please, try again.', true));
}
}
}else{
if(isset ($id) && empty($this->data)){
$this->set('from', 'lead');
$lead = $this->Lead->read(null, $id);
$this->data['Registration']['first_name']
=$lead['Lead']['first_name'];
$this->data['Registration']['middle_name']
=$lead['Lead']['middle_name'];
$this->data['Registration']['last_name']
=$lead['Lead']['last_name'];

$this->data['Registration']['address_line1']
=$lead['Contact']['address_line1'];
$this->data['Registration']['address_line2']
=$lead['Contact']['address_line2'];
$this->data['Registration']['address_line3']
=$lead['Contact']['address_line3'];

$this->data['Registration']['city']
=$lead['Contact']['city'];
$this->data['Registration']['state']
=$lead['Contact']['state'];
$this->data['Registration']['country_name']
=$lead['Contact']['country_name'];

$this->data['Regist

saveAll Problem

2008-07-09 Thread andruu

Hello,

I am having a problem using the saveAll method. I am building a simple
message board application and when trying to use saveAll it hangs for
a few seconds and then shows a white screen with no error.

I have 2 models, ForumThread and ForumPost (ForumPost belongs to
ForumThread and ForumThread hasMany ForumPosts)  and I am trying to
save the two records using saveAll.

Below is the code from my controller and view as well as the array
that is generated by the form.

View:



Post new topic in 
forums

Write your message and submit
create('ForumThread', array('action' => 
'add'))?>
hidden('forum_category_id', array('value' =>
$category['ForumCategory']['id']))?>
input('title', array('class' => 'textbox'))?>
input('ForumPost.body')?>
end('Submit New Post')?>




Controller:

function add() {
if (!empty($this->data)) {
$this->data['ForumPost']['member_id'] = 
$this->Auth->user('id');
$this->data['ForumThread']['member_id'] = 
$this->Auth->user('id');
// pr($this->data); die;
$this->ForumThread->create();
if ($this->ForumThread->saveAll($this->data)) {
$this->Session->setFlash(__('The ForumThread 
has been saved',
true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The ForumThread 
could not be saved.
Please, try again.', true));
}
}
}

Array:

Array
(
[__Token] => Array
(
[key] => 200541b16af308be8275485658b7b69b8041ad95
[fields] => b9a30fa56c5607cf2417083a0ad100db05d56f93
)

[ForumThread] => Array
(
[forum_category_id] => 1
[title] => Test
[member_id] => 1
)

[ForumPost] => Array
(
[body] => Test
[member_id] => 1
)

)

I am also using the Security component if that makes a difference.

Any help is greatly appreciated, Thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---