Luigi, The join table which is the 'extra' table is a common practice and good design principle in when working with databases, when you say it seems like unnecessary work, how will you stop someone inserting a record in your blog favorites that has no relationship to the blog posts table, you would it in code, but if you have a join table that has foreign keys to the two tables you an configure the database to not allow an unknown key to be inserted, this gives you DATA INTEGRITY which is a key part of a well developed application. So your code could attempt to keep things clean and consistent but your DB will not allow records with unmatched keys to be inserted.
I'd suggest reading the book "Database Design for Mere Mortals" for a good idea on well defined schemas. Cheers Grant -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Luigi Sent: Saturday, November 11, 2006 10:24 PM To: Cake PHP Subject: Associations without using foreign key? Hi all, Is there anyway to specify a hasMany or belongsTo association that doesn't use a foreign key? I have two tables: blog_posts: id, author_id, title, text blog_favorites: id, user_id, author_id The idea of blog_favorites is that every user can choose a few favorite authors, and the blog_posts can be queried based on the match between author_id's. However, there are no foreign key available for an association, because in both tables the author_id isn't the primary key. It seems like I would have to build an association through a separate author table, but that just seems like unnecessary work. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
