Re: hasMany findAll alternatives
On 30 mayo, 20:35, uolax [EMAIL PROTECTED] wrote: Thanks so much for any time with this: Forest-hasMany-Trees trees-belongsTo-Forest Do you really have 2 models named forest and tree? I hope not. Try this approach: bind a hasOne association for tree to your forest model, give it a different name than 'tree' e.g. Charlie. $onlyBrown = $this-Forest-findAll(array('Charlie.color' = 'brown')); pr ($onlyBrown); die; hth, AD PS you don't bind to a controller PPS Real class names etc. in future please. --~--~-~--~~~---~--~~ 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: hasMany findAll alternatives
Thank you both for your response. I know these aren't the real class names and whatnotjust trying to put my code in the best hypothetical situation. It's not really forest and treesit's courses (forest) and subjects these courses include (trees). A course can have multiple subjects. i.e. History of Math is both History and Math. Therefore courses hasMany subjects and subjects belongTo courses. Basically, I'm creating a search engine. Because the majority of the info people want to search is in the courses, the main search functionality is in the courses controller. However, I need to make it so someone can search by subject and find the course listed with ALL associated subjects. i.e. I search for courses that have Math, in my results I see History of Math and that it covers both Math and History. The initial trouble came in because I couldn't filter the Subjects in the Courses controller. The hasMany association allows me to filter the subjects, but still displays all courses. Any thoughts? I'll try implement your ideas and see what happens. Thanks, Beau --~--~-~--~~~---~--~~ 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: hasMany findAll alternatives
Oh and I meant bind IN a controllernot to. --~--~-~--~~~---~--~~ 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: hasMany findAll alternatives
Oh and I meant bind IN a controllernot to. --~--~-~--~~~---~--~~ 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: hasMany findAll alternatives
Oh and I meant bind IN a controllernot to. --~--~-~--~~~---~--~~ 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: hasMany findAll alternatives
Oh and I meant bind IN a controllernot to. --~--~-~--~~~---~--~~ 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: hasMany findAll alternatives
Okayhere's what I did. Used AD7six's advise and did a quick unbind from a hasMany and bind a hasOne and did a findAll. This gives me all of the ID's that have the course that was searched for. I then put these ID's in an array and set them as part of the conditions for the next findAll and bring in the other conditions. if( $this-data['Course']['subjarea']!='all'){ $search_termarea = $this-data['Course']['subjarea']; $this-Course-unbindModel(array('hasMany' = array('Coursestocontentarea'))); $this-Course-bindModel(array('hasOne' = array('Coursestocontentarea' = array('className' = 'Coursestocontentarea'; $onlySubj = $this-Course- findAll(array('Coursestocontentarea.content_id' = $search_termarea),'id',null,null,null,1); $hidvarrary = array(); foreach ( $onlySubj as $indivsubj ) { $hidvarrary[] = $indivsubj['Course']['id']; } $conditions['Course.id'] = $hidvarrary; } $this-set('Conditions', $conditions); $this-set('Courses', $this-Course-findAll($conditions, null, null, null, null, 2)); } Not the cleanist, but it works well. Thanks so much! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
hasMany findAll alternatives
Thanks so much for any time with this: Forest-hasMany-Trees trees-belongsTo-Forest I want to: find the forests that only have trees that are brown, (each tree can only belong to one forest) list the other trees in those respective forest, and don't list forests that have no brown trees all from the forests_controller. Obviously I can't use the $conditions[trees][treecolor] = 'brown' in the findAll method as hasMany doesn't seem to be a true joing. I've unsuccesfully tried Bind/Unbind in the Forest Controller, setting the conditions - 'trees.treecolor = brown' while still using hasMany. However, this still returns ALL forests but hides the associated data that doesn't meet the condition. I'm thinking maybe switching this relationship to HABTM using the hasOne/belongsTo on a join table trick, but that seems like overkill as each tree can only belong to one forest even though multiple trees may be brown. ...would the best way to do this be a HABTM table in a quick bind/ unbind in the controller? Any help would be great. Thanks, Beau --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---