Re: hasOne->HABTM save problem

2010-03-05 Thread WebbedIT
Don't go manual otherwise validation of all data before saving becomes
messy.

Can you debug your $this->data array in the controller and show us how
the array is formatted?

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: hasOne->HABTM save problem

2010-03-05 Thread murkyt
Thanks for your reply Paul,

I think that I am trying to get Cake to go too far down the
association chain. I have tried the code you provided and it still
does not save into the HABTM model. I may just have to do a manual
save of the HABTM data.

On Mar 5, 1:08 am, WebbedIT  wrote:
> > Cake's auto-HABTM saving requires the field to be named a particular
> > way in order to recognise it.
>
> I personally get away with the as follows without issue:
> echo $form->input('ClassificationWhat', array('type'=>'select',
> 'multiple'=>'checkbox', 'options'=>array($classificationWhats));
>
> I believe the problem will be trying to use saveAll tow models away
> from the HABTM association as saveAll does not go infinetly deep, it
> only tends to save immideiatly associated records.
>
> Try:
> $this->Sample->ExportSample->saveAll($this->data,
> array('validate'=>'first'));
>
> This should validate/save all 3 models at once returning all your
> required validation errors to your sample form if required.
>
> 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: hasOne->HABTM save problem

2010-03-05 Thread murkyt
Thanks for your reply Robert.

I have the $list['docs'] set up as you describe and I have tried the
multiple select field as ExportDocument.ExportDocument but it seems to
want to attach that data to the Sample model and not the related
ExportSample model which is why I was trying
ExportSample.ExportDocument as the model name for the multiple select
( I have also tried ExportSample.ExportDocument.ExportDocument just in
case!)

On Mar 5, 12:45 am, Robert P  wrote:
> Cake's auto-HABTM saving requires the field to be named a particular
> way in order to recognise it.
>
> Try naming your multiple-select field "ExportDocument.ExportDocument".
>
> $list['docs'] should also be in the format array(ExportDocument.id =>
> name)
>
> --
> Varisan International 
>
> On Mar 5, 8:56 am, murkyt  wrote:
>
>
>
> > I have the following relationships set up for a database of Samples.
> > There are many different types of sample and each type has it's own
> > set of fields so I have modelled them as Supertype/Subtypes with
> > hasOne relationships. For an ExportSample it can have one or more
> > documents tied to it.
>
> > Sample hasOne ExportSample
> > ExportSample HABTM ExportDocuments
>
> > Sample Model:
> > var $hasOne=array
> > (
> >         'ExportSample';
> > )
>
> > ExportSample Model:
> > var $hasAndBelongsToMany=array
> > (
> >         'ExportDocuments'
> > );
>
> > ExportDocuments Model:
> > var $hasAndBelongsToMany=array
> > (
> >         'ExportSample '
> > );
>
> > I have a form that consists of some fields from the Sample, some from
> > the ExportSample and a list of checkboxes for the ExportDocuments .
>
> > echo $form->create('Sample',array('action'=>'addedit'));
> > echo $form->input('Sample.id');
> > echo $form->input('Sample.sampletype_id');
> > echo $form->input('ExportSample.samplesize_id');
> > echo $form->input('ExportSample.sampleform_id');
> > echo $form->input('ExportSample.id');
> > echo $form->input('ExportSample.ExportDocument', array( 'type' =>
> > 'select', 'multiple' => 'checkbox', 'options'=>$lists['docs']));
> > echo $form->end('Save Changes');
>
> > In the controller I am saving the data with...
>
> > $this->Sample->saveAll($this->data);
>
> > When I use this form it saves the Sample data and the Export Sample
> > data from the form but it won't save the HABTM Export Documents. It
> > doesn't run any queries on the HABTM join table at all. If I leave out
> > the ExportSample.id it does save the HABTM data but with an
> > exportsample_id of 0. Put it back in and the HABTM data doesn't save.
>
> > I believe the relationships are set up correctly because running a
> > find operation on the Sample model will show the HABTM ExportDocument
> > data.
>
> > I have successfully used forms in the past with HABTM data and if the
> > Sample model had a HABTM relationship with Export Documents I would
> > have no problems - but in this case the hasOne->hasOne->HABTM
> > relationship seems to screw things up.
>
> > Has anyone come across this before or got any ideas about how I can
> > get this to work?

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: hasOne->HABTM save problem

2010-03-05 Thread WebbedIT
> Cake's auto-HABTM saving requires the field to be named a particular
> way in order to recognise it.

I personally get away with the as follows without issue:
echo $form->input('ClassificationWhat', array('type'=>'select',
'multiple'=>'checkbox', 'options'=>array($classificationWhats));

I believe the problem will be trying to use saveAll tow models away
from the HABTM association as saveAll does not go infinetly deep, it
only tends to save immideiatly associated records.

Try:
$this->Sample->ExportSample->saveAll($this->data,
array('validate'=>'first'));

This should validate/save all 3 models at once returning all your
required validation errors to your sample form if required.

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: hasOne->HABTM save problem

2010-03-05 Thread Robert P
Cake's auto-HABTM saving requires the field to be named a particular
way in order to recognise it.

Try naming your multiple-select field "ExportDocument.ExportDocument".

$list['docs'] should also be in the format array(ExportDocument.id =>
name)

--
Varisan International 

On Mar 5, 8:56 am, murkyt  wrote:
> I have the following relationships set up for a database of Samples.
> There are many different types of sample and each type has it's own
> set of fields so I have modelled them as Supertype/Subtypes with
> hasOne relationships. For an ExportSample it can have one or more
> documents tied to it.
>
> Sample hasOne ExportSample
> ExportSample HABTM ExportDocuments
>
> Sample Model:
> var $hasOne=array
> (
>         'ExportSample';
> )
>
> ExportSample Model:
> var $hasAndBelongsToMany=array
> (
>         'ExportDocuments'
> );
>
> ExportDocuments Model:
> var $hasAndBelongsToMany=array
> (
>         'ExportSample '
> );
>
> I have a form that consists of some fields from the Sample, some from
> the ExportSample and a list of checkboxes for the ExportDocuments .
>
> echo $form->create('Sample',array('action'=>'addedit'));
> echo $form->input('Sample.id');
> echo $form->input('Sample.sampletype_id');
> echo $form->input('ExportSample.samplesize_id');
> echo $form->input('ExportSample.sampleform_id');
> echo $form->input('ExportSample.id');
> echo $form->input('ExportSample.ExportDocument', array( 'type' =>
> 'select', 'multiple' => 'checkbox', 'options'=>$lists['docs']));
> echo $form->end('Save Changes');
>
> In the controller I am saving the data with...
>
> $this->Sample->saveAll($this->data);
>
> When I use this form it saves the Sample data and the Export Sample
> data from the form but it won't save the HABTM Export Documents. It
> doesn't run any queries on the HABTM join table at all. If I leave out
> the ExportSample.id it does save the HABTM data but with an
> exportsample_id of 0. Put it back in and the HABTM data doesn't save.
>
> I believe the relationships are set up correctly because running a
> find operation on the Sample model will show the HABTM ExportDocument
> data.
>
> I have successfully used forms in the past with HABTM data and if the
> Sample model had a HABTM relationship with Export Documents I would
> have no problems - but in this case the hasOne->hasOne->HABTM
> relationship seems to screw things up.
>
> Has anyone come across this before or got any ideas about how I can
> get this to work?

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: hasOne->HABTM save problem

2010-03-05 Thread Robert P
Cake's auto-HABTM saving requires the field to be named a particular
way in order to recognise it.

Try naming your multiple-select field "ExportDocument.ExportDocument".

$list['docs'] should also be in the format array(ExportDocument.id =>
name)

--
Varisan International 

On Mar 5, 8:56 am, murkyt  wrote:
> I have the following relationships set up for a database of Samples.
> There are many different types of sample and each type has it's own
> set of fields so I have modelled them as Supertype/Subtypes with
> hasOne relationships. For an ExportSample it can have one or more
> documents tied to it.
>
> Sample hasOne ExportSample
> ExportSample HABTM ExportDocuments
>
> Sample Model:
> var $hasOne=array
> (
>         'ExportSample';
> )
>
> ExportSample Model:
> var $hasAndBelongsToMany=array
> (
>         'ExportDocuments'
> );
>
> ExportDocuments Model:
> var $hasAndBelongsToMany=array
> (
>         'ExportSample '
> );
>
> I have a form that consists of some fields from the Sample, some from
> the ExportSample and a list of checkboxes for the ExportDocuments .
>
> echo $form->create('Sample',array('action'=>'addedit'));
> echo $form->input('Sample.id');
> echo $form->input('Sample.sampletype_id');
> echo $form->input('ExportSample.samplesize_id');
> echo $form->input('ExportSample.sampleform_id');
> echo $form->input('ExportSample.id');
> echo $form->input('ExportSample.ExportDocument', array( 'type' =>
> 'select', 'multiple' => 'checkbox', 'options'=>$lists['docs']));
> echo $form->end('Save Changes');
>
> In the controller I am saving the data with...
>
> $this->Sample->saveAll($this->data);
>
> When I use this form it saves the Sample data and the Export Sample
> data from the form but it won't save the HABTM Export Documents. It
> doesn't run any queries on the HABTM join table at all. If I leave out
> the ExportSample.id it does save the HABTM data but with an
> exportsample_id of 0. Put it back in and the HABTM data doesn't save.
>
> I believe the relationships are set up correctly because running a
> find operation on the Sample model will show the HABTM ExportDocument
> data.
>
> I have successfully used forms in the past with HABTM data and if the
> Sample model had a HABTM relationship with Export Documents I would
> have no problems - but in this case the hasOne->hasOne->HABTM
> relationship seems to screw things up.
>
> Has anyone come across this before or got any ideas about how I can
> get this to work?

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


hasOne->HABTM save problem

2010-03-04 Thread murkyt
I have the following relationships set up for a database of Samples.
There are many different types of sample and each type has it's own
set of fields so I have modelled them as Supertype/Subtypes with
hasOne relationships. For an ExportSample it can have one or more
documents tied to it.

Sample hasOne ExportSample
ExportSample HABTM ExportDocuments

Sample Model:
var $hasOne=array
(
'ExportSample';
)


ExportSample Model:
var $hasAndBelongsToMany=array
(
'ExportDocuments'
);

ExportDocuments Model:
var $hasAndBelongsToMany=array
(
'ExportSample '
);

I have a form that consists of some fields from the Sample, some from
the ExportSample and a list of checkboxes for the ExportDocuments .

echo $form->create('Sample',array('action'=>'addedit'));
echo $form->input('Sample.id');
echo $form->input('Sample.sampletype_id');
echo $form->input('ExportSample.samplesize_id');
echo $form->input('ExportSample.sampleform_id');
echo $form->input('ExportSample.id');
echo $form->input('ExportSample.ExportDocument', array( 'type' =>
'select', 'multiple' => 'checkbox', 'options'=>$lists['docs']));
echo $form->end('Save Changes');

In the controller I am saving the data with...

$this->Sample->saveAll($this->data);

When I use this form it saves the Sample data and the Export Sample
data from the form but it won't save the HABTM Export Documents. It
doesn't run any queries on the HABTM join table at all. If I leave out
the ExportSample.id it does save the HABTM data but with an
exportsample_id of 0. Put it back in and the HABTM data doesn't save.

I believe the relationships are set up correctly because running a
find operation on the Sample model will show the HABTM ExportDocument
data.

I have successfully used forms in the past with HABTM data and if the
Sample model had a HABTM relationship with Export Documents I would
have no problems - but in this case the hasOne->hasOne->HABTM
relationship seems to screw things up.

Has anyone come across this before or got any ideas about how I can
get this to work?

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