Re: Scary associations with recursive calls
Yes exactly. I tried the expects() and it works like a charm. When recursive calls get too deep, the replicated queries get really scary. On top of that half the time we will not be using most of the data returned as well. It will be really sweet if there is a way to not just specify the Model required but also the fields required. My main question was with such problems, will you guys prefer to not add any association on the Model itself. But use bindModel in your Model and specify the fields required to retrieve the data. This way, you will not be returned with huge amount of data which you do not actually need. It will be sweet if somehow expects() can accept the keys "conditions" and "fields" as well. The another question I was trying to bring up is that in my example, Application belongsTo User and User hasOne Profile. Will you guys actually do things like: bindModel(array( 'belongsTo/hasOne' => array( 'Profile' => array( 'foreignKey' => 'user_id' ) ) ) This will "link" Application direct to the Profile using the user_id field and thus, cake will then LEFT JOIN the Profile instead of making separate queries. Of course, the no longer forces the actual relationship of the models. What say you? Good or Bad practice? On Apr 9, 7:50 pm, Felix Geisendörfer <[EMAIL PROTECTED]> wrote: > > I've used expects() and in my opinion, should become a core feature of > > CakePHP. It feels a lot more natural than the bind and unbinding of > > associations. It's succinct. And because it's built on top of the bind/ > > unbind approach, you can still use it if necessary. > > +1. I could not imagine dealing with big databases without some kind of > Model::expects or unbindAllExcept function. It's very useful indeed. > > -- Felix > --http://www.thinkingphp.orghttp://www.fg-webdesign.de > > jonathan.snook wrote: > > On Apr 9, 12:01 am, "Mariano Iglesias" <[EMAIL PROTECTED]> > > wrote: > > >> This sounds like a scream for help, and expects() is up to the challenge ;) > > >>http://bakery.cakephp.org/articles/view/185 > > > I've used expects() and in my opinion, should become a core feature of > > CakePHP. It feels a lot more natural than the bind and unbinding of > > associations. It's succinct. And because it's built on top of the bind/ > > unbind approach, you can still use it if necessary. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Scary associations with recursive calls
> > I've used expects() and in my opinion, should become a core feature of > CakePHP. It feels a lot more natural than the bind and unbinding of > associations. It's succinct. And because it's built on top of the bind/ > unbind approach, you can still use it if necessary. +1. I could not imagine dealing with big databases without some kind of Model::expects or unbindAllExcept function. It's very useful indeed. -- Felix -- http://www.thinkingphp.org http://www.fg-webdesign.de jonathan.snook wrote: > On Apr 9, 12:01 am, "Mariano Iglesias" <[EMAIL PROTECTED]> > wrote: > >> This sounds like a scream for help, and expects() is up to the challenge ;) >> >> http://bakery.cakephp.org/articles/view/185 >> > > I've used expects() and in my opinion, should become a core feature of > CakePHP. It feels a lot more natural than the bind and unbinding of > associations. It's succinct. And because it's built on top of the bind/ > unbind approach, you can still use it if necessary. > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Scary associations with recursive calls
On Apr 9, 12:01 am, "Mariano Iglesias" <[EMAIL PROTECTED]> wrote: > This sounds like a scream for help, and expects() is up to the challenge ;) > > http://bakery.cakephp.org/articles/view/185 I've used expects() and in my opinion, should become a core feature of CakePHP. It feels a lot more natural than the bind and unbinding of associations. It's succinct. And because it's built on top of the bind/ unbind approach, you can still use it if necessary. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
RE: Scary associations with recursive calls
This sounds like a scream for help, and expects() is up to the challenge ;) http://bakery.cakephp.org/articles/view/185 -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! blog: http://www.MarianoIglesias.com.ar -Mensaje original- De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de Derick Ng Enviado el: Lunes, 09 de Abril de 2007 12:39 a.m. Para: Cake PHP Asunto: Scary associations with recursive calls As models get complicated, I have been thinking at some point that defining association by default in the model gets little to no use. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Scary associations with recursive calls
Hi, As models get complicated, I have been thinking at some point that defining association by default in the model gets little to no use. I understand that the auto-magic queries are what made the association important but the sheer amount of queries just irritates me at times. I end up thinking why wouldn't I just use bindModel in my self defined Model->getSomeData or Model->getOtherData method so only the required data and tables get queried. Now, I understand that with these, the rapid development gets not so rapid. For example of a very simple job application system, this is a model defined according to the actual relationship: [Application] belongsTo - Job - User [Job] belongsTo - Department hasMany - Application [Department] hasMany - Job [User] hasOne - Profile hasMany - Application - Document [Document] belongsTo - User [Profile] belongsTo - User To get a show a list of applications with the relevant profile, I did a Application->findAll() with recursive level of 2. The results goes like: array( [0] => array( [Application] => array( ...data... ) [User] => array( ...data... [Profile] => array( ...data... ) [Application] => array( [0] => array( ...data... ) [1] => array( ...data... ) ) [Document] => array( [0] => array( ...data... ) [1] => array( ...data... ) ) ) [Job] => array( ...data... [Department] => array( ...data... ) [Application] => array( [0] => array( ...data... ) [1] => array( ...data... ) ) ) ) [1] => array( ... more data here ... ) ) Clearly, in such cases when the models are mostly inter-linked, the amount of duplicated information gets scary. I was just trying to get Profile information of the user of each Application to show up but so much more other information gets queried. The most scary one being Job hasMany Application. See how all the applications of the Job applied will get queried each time for each Application listed. The easy way out is to change or remove some association or even add a Application belongsTo Profile association but that will mean the relationship is somewhat awkard since Application really belongsTo a User whom hasOne Profile. Alright, in case my post gets really lengthy (it already is... :p), I hope you guys get the point. So what will you do in this case or rather in general, will you rather not define any association to begin with? Or maybe it will be nice to have a way to specify like i just want Application.User.Profile in my recursive call so I can actually pass that into my findAll() call and magic happens? Despite not knowing CakePHP very well, please let me know if there is anything I can help with. Will be nice to hear from you guys! Cheers, Derick Ng --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---