Raisen
Raisen

Reputation: 4495

Error with join and CakePHP

What am I doing wrong here?

        $sub_data = $this->Subscriber->find('all', array(
            'joins' => array(
                'table' => 'subtypes',
                'alias' => 'Subtype',
                'type' => 'LEFT',
                'conditions' => array(
                    'Subtype.id = Subscriber.plan',
                )
            ),
            'conditions' => array(
                'Subscriber.plan' => $plan['Subtype']['id'],
                'Subscriber.authcode !=' => '',
                'Subscriber.subended' => '0000-00-00 00:00:00',
                'Subtype.authorize_trial_only' => '1',
            )
        ));

Somehow the final statement is not being generated correctly. That's that part where I get a SQL error:

... FROM subscribers AS Subscriber subtypes Subtype LEFT Array WHERE Subscriber.plan = '10' AND Subscriber.authcode != '' AND Subscriber.subended = '0000-00-00 00:00:00' AND Subtype.authorize_trial_only = '1' AND ...

Upvotes: 0

Views: 319

Answers (1)

thesunneversets
thesunneversets

Reputation: 2580

Should it be

 'conditions' => array(
                'Subtype.id' => 'Subscriber.plan',
            )

Or am I just crazy?

EDIT:

Do you perhaps need to add another level of array() in there? i.e.

'joins' => array( array ( 'table' => ...

Upvotes: 1

Related Questions