I would choose separate tables for comments, shoutbox and guestbook.
The reason is that one day soon you might come up with an idea to
expand the guestbook and then you will curse being locked in with the
other models.
For flexibility and reuse of code there is nothing stopping you from
Creating an "AbstractComment" model and let the other concrete models
inherit it.
The flexibility on the View end would be to use elements.
In the Controller you should have little code and any duplication
there would be negligible. But you could always make an abstract
controller if you wanted.
If you were to use a single table then you should (IMHO) use a single
Model and call them all comments (or something). A guestbook would
contain "site owner comments" and the shoutbox "site comments" or
something like it. But since you talk of them as separate entities
then you should probably make several tables.
@harpax
I use that technique a lot. I have some models in my app that are used
by many other models that recide in plugins I have.
You can quite easily use Cake's normal associations with just a simple
change to the association.
var $hasMany = array(
'Reminder' => array(
'className' => 'Reminder',
'foreignKey'=> 'foreign_id',
'conditions'=> array('Reminder.belongs_to' => 'Post'),
'dependent' => true
)
);
Notice that I have set both a foreign key and a condition. That is all
it takes. I advocate using a field named belongs_to instead of
foreign_type and put the exact Model name (or alias) into that field.
This is simply since a type of reminder might be used by more than one
model. Saying that this record belongs to that model reads a little
clearer to me.
/Martin
On May 27, 10:22 am, Braindead <[email protected]> wrote:
> Well, my problem is not directly related to CakePHP, but as it's about
> database design maybe I'll get some good answers.
>
> On my page I have news, downloads and users. These three can be
> commented. Additionally I have a shoutbox and a guestbook. The
> comments, shoutbox and guestbook have all the same fields. So they
> could reside in the same table.
>
> Is it best practice to only have one table for all comments (news,
> downloads, users), the shoutbox and the guestbook and actually filter
> based on a type column? Or is it better to separate everything into
> it's own table?
>
> Using only one table has the advantage, that I could use only one
> controller and a limited set of views, where as using multiple tables
> would mean multiple controllers and duplicated views (as they are all
> nearly the same).
>
> So what do you recomment?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---