On Aug 18, 2006, at 3:54 PM, Rolo D. Monkey wrote:
>
> I know that you cannot save associated records directly from a model
> that has a hasMany relationship, but how do you do it indirectly? I
> have been all over the web for hours looking for this.
>
> Here is a simplified version
>
> Model Member hasMany Individual
> Model Individual belongsTo Member
>
> I am importing data and I can successfully save a new Member. I have
> an array of Individual names, but I don't know how to save them, and
> keep the association intact. Is it some variation of
>
> $this->Member->Individual->save($record);
You should be able to do this if the two are associated.
>
> or do I have to declare
>
> $uses = array("Member", "Individual");
>
> in the MembersController, and then do
>
> $this->Individual->save($record);
This should work as well, but $record['Individual']['member_id']
needs to be populated with the right ID.
> If so, how do I get the id of the member I just saved?
Model::getLastInsertId()
http://manual.cakephp.org/chapter/models
> By the way, CakePHP is awesome, and it has already saved me weeks
> worth
> of work, but there are massive holes in the documentation on simple
> stuff like this.
Yeah, the docs have some holes, but this is addressed in the "Saving
Your Data" section of the URL provided above.
Hope this works for you.
-- John
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---