On Feb 12, 2011, at 00:43, ShadowCross wrote: > Note that the individual tables books, messages, posts DOES NOT have a > content_id field, but the contents table would have the fields 'model' > and 'model_id'. This results in a content record that can only be ONE > of either book, message, or post. In your proposed table schema, > where all three tables have content_id, you would have a content > record that can be any or all of the above, which is probably not what > you want.
I've heard that recommended before. Is that really the best practice? (I honestly don't know, and am trying to learn.) It surprises me, because it means that I cannot (in my database engine) declare a foreign key on the model_id column, which means I lose the benefits that in-database foreign key definitions provide. It also seems to waste space, storing the model name string over and over again in every record. If I were designing this, I think my contents table would have fields bookmark_id, message_id and post_id, each of which is defined as allowing NULL, with the intention that only one of these be filled for any given record; I'd have a beforeSave() method in the Content model ensuring that. Does that make sense, or is there a reason why I wouldn't want to do it that way? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
