Tuesday, May 4, 2010

Re: The docs for Containable does not work for complex search. Complex search is 2 models away. For cake 1.3

Being a newbie to cakephp myself, I found out that by trying to help out other people I get to learn it better and faster. I did pay attention but, as I told you, I'm not having a good time right now and most probably that's why I didn't get you problem the first time.

Feelings aside :), here is how I do things when it comes to complex-ish queries. First, I try the recursive = 2 and a debug  on the var to see exactly how much data I'm getting and how much do I need to take out. That's why I was bugging you with that. When you have the debugged array in from of you it's very easy to write the containable query.

First, attach Containable on the fly in the view action:
$this->Merchant->attach('Containable');

Then the query:

$merchant = $this->Merchant->find('first', array(
                                            'contain' => array(
                                                            'User' => array('conditions' => array('User.email' => $email)),
                                                            'Domain' => array('conditions' => array('Domain.primary' => $primary)),
                                                            'Shop'
                                                         ),
                                            'conditions' => array('Merchant.owner' => $owner)
                                           )
                                  );

I've wrote this blindfolded and I have no idea if it will work, but i think it's a good start. I'll test case it myself if it's necessary.


On Tue, May 4, 2010 at 3:48 PM, Kei Simone <kimcity@gmail.com> wrote:
Hi Andrei,

my first kneejerk feeling is that you are not paying attention to my
previous reply with the schema attached.

but i am going to ignore that feeling and assume that probably it was
my communication that was bad.

1) let me rephrase the schema again.

User
 -id
 -email
 -password
 -name

Merchant
 -id
 -user_id
 -shop_id
 -owner

Shop
 -id
 -name
 -description

Domain
 -id
 -domain
 -primary

Once again, the associations are that:
 User hasOne Merchant
 Shop hasMany Merchant
 Shop hasMany Domain

I am looking to grab data from Merchant model.

The conditions are

Domain.primary =1
User.email = a@a.com
Merchant.owner = 1

I want to grab the FIRST data row that matches the conditions.

the datarow must have data from all 4 models.

2)

No i have not tried the find all with recursive 2

there are 3 reasons:

1) my joins is already working. my purpose in starting this thread is
to see if

a) i can do it in containable because i am forseeing a lot of similar
(complex find) situations cropping up down the line and if Containable
behavior is core then there must be a good reason to use it over
joins.

b) i REALLY REALLY want to get better at cakephp hence understanding
and studying Containable a core behavior is essential

since my joins is already working i have less inclination to try out
the find all with recursive 2.

2) my merchants and shops and users model have 4 to 6 Other models
tied to them EACH.

Recursive 2 would be mean retrieving a lot of data. I am assuming this
from the docs i read in book.cakephp.org esp the articles on
Containable. in fact this is the very reason why Containable was
promoted to solve this very same issue.

Unless of course i misinterpret your meaning. then i shall try it out.
but only if you give me exact details.

I am a 1 month old in terms of cake usage despite reading the docs
extensively i may still need quite a bit of hand holding.

3) i want to find the first datarow that matches the condition not
ALL. minor point of course i could easily change it to find first with
recursive 2 but then reason 2 would still stand.


I am truly sorry if what i said is rude or offends you. At work and at
home, i have been labelled as harsh and insensitive.

At times i wonder if i am autistic.

But this (obsessive) search to understand how the heck to get complex
search right and get a true understanding of cake is driving me to go
full out to seek answers so please forgive me should you be offended.

Thank you.

On May 4, 7:49 pm, Andrei Mita <andrei.m...@gmail.com> wrote:
> I'm having a hard time understanding your problem, probably it's just me,
> I'm not having a good time at work.
>
>

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: