hi working kind of large project have 5 tables needs work with. scenario want list posts in posts table , comments particular post. each comment has author, need there information too. make easy
post 1
-> post description [take posts table]
-> comments related post 1[take comments table, has post_id foreign key]
-> commented user information [comment table has user_id foreign key]
post 2
-> post description [take posts table]
-> comments related post 2[take comments table, has post_id foreign key]
-> commented user information [comment table has user_id foreign key]
.
.
.
post {n}
-> post description [take posts table]
-> comments related post {n}[take comments table, has post_id foreign key]
-> commented user information [comment table has user_id foreign key]
assume have on 10000 posts in table
can 1 me work this.
also thought create table view database layer task
provided have model relations set correctly (i won't go detail on because cakephp book excellent reference on matter), relatively simple.
to able user data each comment post well, you'll have use containable. again, won't explain because book can better.
i'm providing sample query below, though cautioned may not 100% correct (especially considering not know names of columns):
$data = $this->post->find('all', array( 'fields' => array('post.description'), 'contains' => array( 'comments', 'commenter' //alias user model ) ));
just explaination of comment above: assumes comment hasone commenter => array('classname' => 'user')
Comments
Post a Comment