I’m learning CakePHP, thus I’m making a simple blog in order to learn basic functionality, this blog will have tables holding posts, users, users activation codes and taxonomy along with taxonomy relationships between posts and tags.
Ok, the thing now is, I’ve managed to set everything up properly and every time I fetch a post, it returns a lot of data:
Array
(
[Post] => Array
(
[post_id] => 1
[post_title] => Test 1
[post_nice_name] => test-1
[post_author] => 1
[post_content] => I'm testing this piece of crap.
[post_creation_time] => 2011-11-13 22:50:05
[post_last_modification] => 2011-11-13 22:50:05
[post_allow_comments] => 1
[post_allow_trackback] => 1
[post_display] => 1
)
[User] => Array
(
[user_id] => 1
[user_email] => XX@XXXXXXXXXXx.XX.XX
[user_password] => XXXXXXXXXXXXXXXXXX
[user_creation_time] => 2011-11-13 10:48:10
[user_last_login] => 2011-11-13 22:49:21
[user_birthday] => 1993-08-24 03:00:00
)
[TaxonomyTags] => Array
(
[0] => Array
(
[tag_id] => 1
[tag_name] => test1
[tag_description] => This tag is a test
[PostsTaxonomyTag] => Array
(
[relation_id] => 1
[post_id] => 1
[taxonomy_tag_id] => 1
)
)
[1] => Array
(
[tag_id] => 2
[tag_name] => test2
[tag_description] => This tag is just another test.
[PostsTaxonomyTag] => Array
(
[relation_id] => 2
[post_id] => 1
[taxonomy_tag_id] => 2
)
)
)
)
This much data is really unnecessary: I don’t need the PostsTaxonomyTag array for every tag, nor do I need that much of the user’s information, I don’t even need some of the post’s information!. So I wanted to know if there’s any way to filter this information before it is passed on to the view.
You can unbind models befor a find function to prevent unneeded data
I prefer to use the containable behavior for most models which forces you to state the relationships you need at find though. Mcheck the docs about that behavior.
You can set conditions, order, etc. in the containable set making it powerful for getting exactly the data you need.