I discovered my error here:
NOTE ABOVE:
'conditions' => 'Staff.id = Property.staff_id',
'conditions' => '',
I removed the second conditions and it now works.
On Jul 8, 4:04 pm, elogic <[email protected]> wrote:
> Hi All,
>
> I am having some issues trying to get the data I need in my view
> pages.
>
> My basic structure is as follows (simplified):
>
> ACCOUNTS
> id
> name
> etc
>
> PROPERTIES
> id
> estate_id (This is linked to a record in ACCOUNTS)
> staff_id (This is linked to a record in ACCOUNTS)
> etc
>
> in my property model I have the following which seems close, it will
> call the right estate person but then it tries the staff and I am
> getting many property records coming though and the SQL in the log is
> below (note the issue I think is the (LEFT JOIN `accounts` AS `Staff`
> ON (1 = 1)):
>
> PROPERTY MODEL
> var $belongsTo = array(
> 'Estate' => array(
> 'className' => 'Account',
> 'foreignKey' => false,
> 'conditions' => 'Estate.id = Property.estate_id',
> 'fields' => '',
> 'order' => ''
> ),
> 'Staff' => array(
> 'className' => 'Account',
> 'foreignKey' => false,
> 'conditions' => 'Staff.id = Property.staff_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );
>
> SQL FOR ABOVE
> SELECT `Property`.`id`, `Property`.`lease_name`,
> `Property`.`salutation`, `Property`.`mobile`, `Property`.`email`,
> `Property`.`street1`, `Property`.`street2`, `Property`.`suburb`,
> `Property`.`state`, `Property`.`postcode`, `Property`.`owner_name`,
> `Property`.`lease_date`, `Property`.`rent_amount`,
> `Property`.`estate_id`, `Property`.`staff_id`,
> `Property`.`entry_date`, `Property`.`entry_time`,
> `Property`.`timestamp`, `Estate`.`id`, `Estate`.`first_name`,
> `Estate`.`last_name`, `Estate`.`company`, `Estate`.`email`,
> `Estate`.`mobile`, `Estate`.`phone`, `Estate`.`timestamp`,
> `Staff`.`id`, `Staff`.`first_name`, `Staff`.`last_name`,
> `Staff`.`company`, `Staff`.`email`, `Staff`.`mobile`, `Staff`.`phone`,
> `Staff`.`timestamp` FROM `properties` AS `Property` LEFT JOIN
> `accounts` AS `Estate` ON (`Estate`.`id` = `Property`.`estate_id`)
> LEFT JOIN `accounts` AS `Staff` ON (1 = 1) WHERE 1 = 1 LIMIT 20
>
> Can anyone see where I am going wrong? Once I get this going I then
> have a few other issues but this is the main one so I want to focus on
> it.
>
> Thankyou
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php