Saturday, October 2, 2010

unbind USER model inside the USER controller

Then, I have a User model and a Book Model I bind it as:
User HABTM Book
Book HABTM User

So I have books_users table inside my DB and CAKEPHP will
automatically create BooksUser virtual model.

Now if I want to know about a user's book collection I call method
getCollection inside User controller. This work QUITE perfectly and
will return me a data set like:
Array
(
[0] => Array
(
[BooksUser] => Array
(
[id] => 4ca75919
)

[Book] => Array
(
[id] => 6a915e32
[title] => the Dubliners
)

[User] => Array
(
[0] => Array
(
[id] => 4ca3183d
[BooksUser] => Array
(
[id] => 4ca75919
)

)
);

This return me what I need, but there is even [User] information.
Inside this array there will be all users that own that book, this
will mean a lot of unuseful information and a lot of unuseful load.
How can I unbind it?
The real problem is that I need to unbind model User from User
controller, I can do that? Otherwise, what can I do?

PS: I have thing to remove [User] using PHP unset() function. In this
way there will be less data send to view, but I think that simply
unbinding model will increase performance?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: