I see what you mean. My eyes glazed over. :-)

How about posting the output of debug($this->paginate) (after you've
set the conditions)?

On Sun, Sep 13, 2009 at 4:41 PM, martinp <he...@martinpetts.com> wrote:
>
> It's quite complicated as I have to deal with some craziness in the
> form search form submission. I don't think this is the problem, but
> here's the function that sorts out the conditions:
>
>        private function setPreConditions() {
>                $preConditions = $this->postConditions($this->data);
>                unset($preConditions['Search.search']);
>                $facilitiesConditions = array();
>                if(!empty($preConditions)) {
>                        foreach($preConditions as $key => $value) {
>                                if(empty($value)) {
>                                        unset($preConditions[$key]);
>                                } else {
>                                        if(substr($key, 0, 14) == 
> 'SchoolFacility') {
>                                                $facility_name = substr($key, 
> 15);
>                                                
> $facilitiesConditions[]['School.facilities LIKE ?'] = "%
> \"$facility_name\";s:1:\"1\";%";
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'School.name') {
>                                                $preConditions[]['or'] = 
> array('LOWER(School.name) LIKE' =>
> '%'.low($value).'%', 'LOWER(Course.name) LIKE' => '%'.low($value).'%',
> 'LOWER(CourseType.name) LIKE' => '%'.low($value).'%', 'LOWER
> (CourseQualification.name) LIKE' => '%'.low($value).'%', 'LOWER
> (CourseLevelMin.name) LIKE' => '%'.low($value).'%');
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Course.start_time') {
>                                                switch($value) {
>                                                        case 'AM':
>                                                                
> $preConditions[]['or'] = array('Course.start_time <' =>
> '12:00:00', 'Course.start_time' => null);
>                                                                break;
>                                                        case 'PM':
>                                                                
> $preConditions[]['or'] = array('Course.start_time >=' =>
> '12:00:00', 'Course.start_time' => null);
>                                                                break;
>                                                }
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Course.max_class_size') {
>                                                
> $preConditions['Course.max_class_size <='] = $value;
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Course.course_level_min') {
>                                                $preConditions[]['or'] = 
> array('CourseLevelMin.order <=' =>
> $value, 'Course.course_level_min' => null);
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Student.age') {
>                                                $preConditions[]['or'] = 
> array('Course.minimum_age <=' =>
> $value, 'Course.minimum_age' => null);
>                                                $preConditions[]['or'] = 
> array('Course.maximum_age >=' =>
> $value, 'Course.maximum_age' => null);
>                                                $preConditions[]['or'] = 
> array('Accommodation.minimum_age <=' =>
> $value, 'Accommodation.minimum_age' => null);
>                                                $preConditions[]['or'] = 
> array('Accommodation.maximum_age >=' =>
> $value, 'Accommodation.maximum_age' => null);
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Course.lessons_per_week') {
>                                                switch($value) {
>                                                        case 1:
>                                                                
> $preConditions['Course.lessons_per_week <='] = 10;
>                                                                break;
>                                                        case 2:
>                                                                
> $preConditions['Course.lessons_per_week >='] = 10;
>                                                                
> $preConditions['Course.lessons_per_week <='] = 15;
>                                                                break;
>                                                        case 3:
>                                                                
> $preConditions['Course.lessons_per_week >'] = 15;
>                                                                
> $preConditions['Course.lessons_per_week <='] = 20;
>                                                                break;
>                                                        case 4:
>                                                                
> $preConditions['Course.lessons_per_week >'] = 20;
>                                                                break;
>                                                }
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Search.view') {
>                                                unset($preConditions[$key]);
>                                        }
>                                        if($key == 'Course.no_of_weeks') {
>                                                
> $preConditions['CourseFee.week_'.$value.' >'] = 0;
>                                                $preConditions[]['or'] = 
> array('Accommodation.minimum_stay <='
> => $value, 'Accommodation.minimum_stay' => null);
>                                                $preConditions[]['or'] = 
> array('Accommodation.maximum_stay >='
> => $value, 'Accommodation.maximum_stay' => null);
>                                        }
>                                }
>                        }
>                }
>                $preConditions[] = $facilitiesConditions;
>                $preConditions[] = array('Course.published' => 1);
>                return $preConditions;
>        }
>
> On Sep 12, 3:25 pm, brian <bally.z...@gmail.com> wrote:
>> I missed Miles's post, also. I, too, think your $conditions looks
>> strange. Can you post the actual code (not debug output)?
>>
>> On Fri, Sep 11, 2009 at 11:57 AM,martinp<he...@martinpetts.com> wrote:
>>
>> > Hello
>>
>> > Thanks for your replies. I thought I was watching this topic, but
>> > wasn't aware that the discussion had continued without me!
>>
>> > Brian - I think you've hit the nail on the head regarding my
>> > containment problem, but I still don't have it working.
>> > Miles J - I assure you they are all belongsTo associations. What is
>> > wrong with my conditions array?
>>
>> > I've stripped it back a bit to try and get the 'School' association
>> > working first. Here's what I have:
>>
>> >                $this->paginate['CourseResult'] = array(
>> >                        'fields' => array(
>> >                                'CourseResult.id',
>> >                                'CourseResult.course_id',
>> >                                'CourseResult.no_of_weeks',
>> >                                'CourseResult.year',
>> >                                'CourseResult.price'
>> >                        ),
>> >                        'contain' => array(
>> >                                'Course' => array(
>> >                                        'fields' => array(
>> >                                                'Course.id',
>> >                                                'Course.school_id',
>> >                                                'Course.name',
>> >                                                'Course.course_language_id',
>> >                                                'Course.course_type_id',
>> >                                                
>> > 'Course.course_qualification_id',
>> >                                                'Course.course_level_min',
>> >                                                'Course.course_level_max',
>> >                                                'Course.published',
>> >                                                'Course.deleted'
>> >                                        ),
>> >                                        'School' => array(
>> >                                                'fields' => array(
>> >                                                        'School.id',
>> >                                                        'School.name',
>> >                                                        'School.city',
>> >                                                        'School.country_id'
>> >                                                )
>> >                                        )
>> >                                )
>> >                        ),
>> >                        'conditions' => $conditions
>> >                );
>> >                $rows = $this->paginate('CourseResult');
>>
>> > Working with the same conditions as above and with the same result.
>>
>> > On Sep 4, 9:31 pm, Miles J <mileswjohn...@gmail.com> wrote:
>> >> Correct me if im wrong, but are you allowed to use $conditions the way
>> >> he is? On top of that, I feel like were not seeing all the queries,
>> >> all of those associations cant be belongsTo.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to