Hey guys,
I'm quite new to cake and MVC Patterns in general. At the moment I'm
playing around a bit to figure out how cake works. My plan was to
build a little forum for learning. But I already fail when designing
the models :/

I got the following (sql) tables:

forums (id, category_id, lastpost_id, etc...)
forum_threads(id, forum_id, firstpost_id, firstpost_user_id,
lastpost_id, lastpost_user_id, etc...)
forum_posts(id, user_id, thread_id, last_user_edit_id, etc...)
forum_categories(id, etc..)
users(id, etc...)

What would be the cake models like? And how can I optimize them?
The logic is like that (using the table names):

forum_categories hasMany forums
forums hasMany forum_threads
forum_threads hasMany forum_posts

forum_posts belongsTo forum_threads, users (user_id), users
(last_user_edit_id)
forum_threads belongsTo forums, users (firstpost_user_id), users
(lastpost_user_id), forum_posts (firstpost_id),
forum_posts(lastpost_id)
forums belongsTo forum_categories

What about cake conventions? Is it good to name the tables like that?

And what about multiple joining of the same table. For example in
forum_threads where I need different users (firstpost user and
lastpost user). Is that ok, or are there any other technics?

My ForumThread (forum_thread?) model would look like that?

        var $belongsTo = array(
                        'Forum' => array('className' => 'Forum', 'foreignKey' =>
'forum_id'),
                        'FirtstpostUser' => array('className' => 'User', 
'foreignKey' =>
'firstpost_user_id'),
                        'LastpostUser' => array('className' => 'User', 
'foreignKey' =>
'lastpost_user_id'),
                        'Firstpost' => array('className' => 'ForumPost', 
'foreignKey' =>
'firstpost_id'),
                        'Lastpost' => array('className' => 'ForumPost', 
'foreignKey' =>
'lastpost_id')
        );

        var $hasMany = array(
                        'ForumPost' => array('className' => 'ForumPost', 
'foreignKey' =>
'thread_id')
        );

What about conditions and fields? Any optimizations?

I noticed that foreignKey has a diffenrent meaning in the "hasMany"
statement compared to "belongsTo". In hasMany its the linked table's
key ("thread_id" in "forum_posts") and in belongsTo its the own
table's key ("forum_id" in "forum_threads"). Is it always like that?
Sorry, that might be a stupid question, but I still dont understand
the whole thing in total... ;)

Thanks in advance for the help!
Matthias

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to