Thank you so very much for your time trying to cipher this out for me
John!

I had already begun to fear that I was trying to do the impossible
here. I have also been working in parallel on an alternate data entry
scheme where we would have to run multiple passes over the data set
(currently on index cards of all things) to enter all clones and all
populations first, then enter the relationships between them on a
subsequent pass.

However, I will also now think about a multi-step data entry process
as you suggest.

Thanx again, DaveT.

On Feb 18, 3:24 pm, John Andersen <[email protected]> wrote:
> In that case, in my opinion, you can't save all the information in one
> go!
> You can't save from the Pop models side as the relationship to Clon
> goes through Mated, and it is not an ordinary HABTM relationship
> (which it also can't be defined as). The same goes when trying to save
> from the Clon models side.
>
> My suggestion is to save the Clon first as individual saves, not
> together with the Mated or Pop data.
> Then make a saveAll from the Pop model with the Mated data together
> with the Clon primary keys.
> Something like:
> [pseudo code]
> foreach clon in the data:
>    save the clon - remember id;
>
> Add the remembered clon ids to the mated data.
> Save the pop together with mated.
> [/pseudocode]
>
> Hope the above helps you on the way,
>    John
>
> On Feb 18, 9:35 pm, McScreech <[email protected]> wrote:
>
> > YES!!! Exactly that!
> > With each Pop and Clon to be saved in their respective tables (if they
> > don't already exist) and the relationship saved in the Mated table.
>
> > DaveT.
>
> > On Feb 18, 2:12 pm, John Andersen <[email protected]> wrote:
>
> > > Thanks, now to understand what you are trying to do - in the view, are
> > > you trying to define that one Pop may be related to a mated Father and
> > > Mother?
> > > Where the Father is defined as one Clon (FatherClone), and the Mother
> > > is defined as one Clon (MotherClone) - all to be saved as one combined
> > > relationship in Mated.
> > > Am understanding you correctly?
> > >    John
>
> > > On Feb 18, 8:22 pm, McScreech <[email protected]> wrote:
>
> > > > Yes, it is a bit of a complicated tangle isn't it!
> > > > Excerpts of the related tables and models are:
> > > > <?php
> > > > CREATE TABLE clons (
> > > >         id INT NOT NULL AUTO_INCREMENT,
> > > >         `name` CHAR(10) NOT NULL,
> > > >         /* 18 other fields omitted */
> > > > ) ENGINE = InnoDB;
>
> > > > class Clon extends AppModel {
> > > >         var $name = 'Clon';
> > > >         /* validation rules omitted */
> > > >         /* 2 other belongsTo relations omitted */
> > > >         var $hasMany = array(
> > > >                 'MotherClone' => array( /* Link clon back to mated */
> > > >                         'className' => 'Mated',
> > > >                         'foreignKey' => 'mother_id',
> > > >                         'dependent' => false
> > > >                 ),
> > > >                 'FatherClone' => array( /* Link clon back to mated */
> > > >                         'className' => 'Mated',
> > > >                         'foreignKey' => 'father_id',
> > > >                         'dependent' => false
> > > >                 )
> > > >         ); // end $hasMany
> > > >         /* 3 other hasMany relations omitted */
>
> > > > } // end class Clon
>
> > > > CREATE TABLE mated (
> > > >         /* complete listing */
> > > >         id INT NOT NULL AUTO_INCREMENT,
> > > >         mother_id INT DEFAULT NULL,
> > > >         father_id INT DEFAULT NULL,
> > > >         pop_id INT DEFAULT NULL,
> > > >         `date` DATE NOT NULL DEFAULT '0000-00-00',
> > > >         PRIMARY KEY (id),
> > > >         KEY fk_mother (mother_id),
> > > >         KEY fk_father (father_id),
> > > >         KEY fk_pop (pop_id)
> > > > ) ENGINE = InnoDB;
>
> > > > class Mated extends AppModel {
> > > >         var $name = 'Mated';
> > > >         /* validation rules omitted-otherwise complete listing */
> > > >         var $belongsTo = array(
> > > >                 'Mother' => array( /* Link mated to clon */
> > > >                         'className' => 'Clon',
> > > >                         'foreignKey' => 'mother_id'
> > > >                 ),
> > > >                 'Father' => array( /* Link mated to clon */
> > > >                         'className' => 'Clon',
> > > >                         'foreignKey' => 'father_id'
> > > >                 ),
> > > >                 'Pop' => array(
> > > >                         'className' => 'Pop',
> > > >                         'foreignKey' => 'pop_id'
> > > >                 )
> > > >         ); // end $belongsTo
>
> > > > } // end class Mated
>
> > > > CREATE TABLE pops (
> > > >         id INT NOT NULL AUTO_INCREMENT,
> > > >         `name` CHAR(10) NOT NULL,
> > > >         /* 13 other fields omitted */
> > > > ) ENGINE = InnoDB;
>
> > > > class Pop extends AppModel {
> > > >         var $name = 'Pop';
> > > >         /* validation rules omitted */
> > > >         /* 2 other belongsTo relations omitted */
> > > >         var $hasMany = array(
> > > >                 'Mated' => array(
> > > >                         'className' => 'Mated',
> > > >                         'foreignKey' => 'pop_id',
> > > >                         'dependent' => false
> > > >                 )
> > > >         ); // end $hasMany
> > > >         /* 3 other hasMany relations omitted */
>
> > > > } // end class Pop
>
> > > > TIA, DaveT.
>
> > > [snip]

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 [email protected]
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

Reply via email to