Re: Model Heirarchy and Quering
On 23 mayo, 01:23, Brian Hartvigsen [EMAIL PROTECTED] wrote: I have 3 models, Group, User, Referral. Group hasMany User, User hasMany File. I have some Users that I want to be able to see all Files for other Users in their Group. Right now I'm trying to do this with $users = $this-User-findAll('group_id = ' . $User['group_id']); $this-File-findAll(array('File.user_id' = $users)); Hi Brian, $constraint = array( 'User.group_id'=$User['group_id'], 'NOT' = array('User.id' = $User['id']) ); //EITHER: $this-User-displayField = 'id'; $users = $this-User-generateList($constraint); //OR $users = $this-User- generateList($constraint,null,null,null,'{n}.User.id'); //FOLLOWED BY $data = $this-File-findAll(array('File.user_id' = $users)); //pr ($data); die; Obviously this isn't working. The $users array is in the wrong format for use in a conditions statement (even if I restrict it to grabbing id only in the first findAll.) Am I expecting to much here or simply going about this the wrong way? I'll go for option 2. :D. hth, AD --~--~-~--~~~---~--~~ 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: Model Heirarchy and Quering
So it turns out I'm just making things harder than they need to be: $data = $this-File-findAll('User.group_id='.$this-Session- read('User.User.group_id')); I realize this only works because of recursion, but so far, it's the best solution I have, and I need the recursive data anyway to display all the information to the users. Just so you know I tried the findAll as AD suggested. The second findAll never showed any conditions in the WHERE clause and so would retrieve all Files. After racking my brain for a while and staring at the SQL output I realized I was just doing it the hard way :P --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Model Heirarchy and Quering
I have 3 models, Group, User, Referral. Group hasMany User, User hasMany File. I have some Users that I want to be able to see all Files for other Users in their Group. Right now I'm trying to do this with $users = $this-User-findAll('group_id = ' . $User['group_id']); $this-File-findAll(array('File.user_id' = $users)); Obviously this isn't working. The $users array is in the wrong format for use in a conditions statement (even if I restrict it to grabbing id only in the first findAll.) Am I expecting to much here or simply going about this the wrong way? --~--~-~--~~~---~--~~ 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: Model Heirarchy and Quering
Hi Brian Have a look at the Conditions section of the Model page in the manual. It will give you a thorough explanation of how to construct the kind of complex conditions statement that you want (hint, this would use an SQL IN condition - which the manual covers). Given what you are trying to do I expect that you will have to rework it to get the right structure to use in the conditions. There may be an automagical way in Cake to convert a result set to a conditions array, but I don't know it. I just loop over the array and reform the data the way that I need it. Regards, Langdon Brian Hartvigsen wrote: I have 3 models, Group, User, Referral. Group hasMany User, User hasMany File. I have some Users that I want to be able to see all Files for other Users in their Group. Right now I'm trying to do this with $users = $this-User-findAll('group_id = ' . $User['group_id']); $this-File-findAll(array('File.user_id' = $users)); Obviously this isn't working. The $users array is in the wrong format for use in a conditions statement (even if I restrict it to grabbing id only in the first findAll.) Am I expecting to much here or simply going about this the wrong way? --~--~-~--~~~---~--~~ 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: Model Heirarchy and Quering
Set $recursive = 2 in your Group model. See the manual. On May 22, 9:18 pm, Langdon Stevenson [EMAIL PROTECTED] wrote: Hi Brian Have a look at the Conditions section of the Model page in the manual. It will give you a thorough explanation of how to construct the kind of complex conditions statement that you want (hint, this would use an SQL IN condition - which the manual covers). Given what you are trying to do I expect that you will have to rework it to get the right structure to use in the conditions. There may be an automagical way in Cake to convert a result set to a conditions array, but I don't know it. I just loop over the array and reform the data the way that I need it. Regards, Langdon Brian Hartvigsen wrote: I have 3 models, Group, User, Referral. Group hasMany User, User hasMany File. I have some Users that I want to be able to see all Files for other Users in their Group. Right now I'm trying to do this with $users = $this-User-findAll('group_id = ' . $User['group_id']); $this-File-findAll(array('File.user_id' = $users)); Obviously this isn't working. The $users array is in the wrong format for use in a conditions statement (even if I restrict it to grabbing id only in the first findAll.) Am I expecting to much here or simply going about this the wrong way? --~--~-~--~~~---~--~~ 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: Model Heirarchy and Quering
I was trying to see if there was a way to do it within cake without a ton of iteration, but so far it appears that I'm going to have to do some data cleanup one way or another. $recursive = 2 would retrieve all the data, but wouldn't allow it to be sorted directly, I would have to go iterate over the Group-User array adding each of thier File parts into a global array and then sort that. I kinda thought I was going to have to clean up the data (as suggested by Langdon), really just wondering if there was a cleaner way to do it I guess. I actually got the idea for the findAll() to findAll() search from reading the manual on Models and conditions in particular when I first realized this was going to be an issue. -- Brian On May 22, 10:03 pm, Joshua McFarren [EMAIL PROTECTED] wrote: Set $recursive = 2 in your Group model. See the manual. On May 22, 9:18 pm, Langdon Stevenson [EMAIL PROTECTED] wrote: Hi Brian Have a look at the Conditions section of the Model page in the manual. It will give you a thorough explanation of how to construct the kind of complex conditions statement that you want (hint, this would use an SQL IN condition - which the manual covers). Given what you are trying to do I expect that you will have to rework it to get the right structure to use in the conditions. There may be an automagical way in Cake to convert a result set to a conditions array, but I don't know it. I just loop over the array and reform the data the way that I need it. Regards, Langdon Brian Hartvigsen wrote: I have 3 models, Group, User, Referral. Group hasMany User, User hasMany File. I have some Users that I want to be able to see all Files for other Users in their Group. Right now I'm trying to do this with $users = $this-User-findAll('group_id = ' . $User['group_id']); $this-File-findAll(array('File.user_id' = $users)); Obviously this isn't working. The $users array is in the wrong format for use in a conditions statement (even if I restrict it to grabbing id only in the first findAll.) Am I expecting to much here or simply going about this the wrong way? --~--~-~--~~~---~--~~ 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: Model Heirarchy and Quering
Hi Brian As mentioned, I don't know of a Cake way of doing it, but if you discover one then I am all ears :-) Regards, Langdon Brian Hartvigsen wrote: I was trying to see if there was a way to do it within cake without a ton of iteration, but so far it appears that I'm going to have to do some data cleanup one way or another. $recursive = 2 would retrieve all the data, but wouldn't allow it to be sorted directly, I would have to go iterate over the Group-User array adding each of thier File parts into a global array and then sort that. I kinda thought I was going to have to clean up the data (as suggested by Langdon), really just wondering if there was a cleaner way to do it I guess. I actually got the idea for the findAll() to findAll() search from reading the manual on Models and conditions in particular when I first realized this was going to be an issue. -- Brian --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---