Monday, December 20, 2010

How can I add to one table while I'm adding to another

Here is the scenario based on a simple blog:

The model for the blog is called Post. Post has the following fields:
id, title, body, created, modified. There are two other related
models: Tag and Comment. Tag has the following fields: id, name,
created, modified. Comment has the following fields: id, name, email,
body, blog_id, created, modified.

These are the associations: Post hasMany Comment, Post
hasAndBelongsToMany Tag, Tag hasAndBelongsToMany Post, Comment
belongsTo Post.

Therefore another table is required to keep track of the associations
between Post and Tag. The posts_tags table has the following fields:
post_id, tag_id.

So let's say I want to write a new blog Post. And let's say I want to
add some new tags that already are not in the table. How do I do that?
How do I add to two tables at the same time?


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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate