I need to know the cakeish way of adding the from Features_properties. so when I do
where FeaturesProperty
.feature_id
= 3
it won't give an error
The below will generate a MySQL query
$this->Paginator->settings = array('conditions' => array($conditionID, $categoryID, $localityID, $serviceTypeID,
'Property.price BETWEEN ' . $params['priceFrom'] . ' AND ' . params['priceTo'],
$bedrooms,$bathrooms,'FeaturesProperty.feature_id = 3','Property.viewable = 1'),
'contain' => array('Image' => array('conditions' => array('main_image' => true)),
'ServiceType','Category','FeaturesProperty', 'Condition', 'Locality',),
'limit' => 15);
Which can be seen hereunder
SELECT `Property`.`id`, `Property`.`address1`, `Property`.`address2`,
`Property`.`area`, `Property`.`category_id`, `Property`.`condition_id`,
`Property`.`contact_detail_id`, `Property`.`country_id`, `Property`.`description`,
`Property`.`length`, `Property`.`main_image_id`, `Property`.`price`,
`Property`.`service_type_id`, `Property`.`locality_id`, `Property`.`viewable`,
`Property`.`width`, `Property`.`bathroom_qty`, `Property`.`bedroom_qty`,
`Category`.`id`, `Category`.`category`, `Condition`.`id`, `Condition`.`condition`,
`ServiceType`.`id`, `ServiceType`.`service_type`, `Locality`.`id`,
`Locality`.`locality`, `Locality`.`region_id`, (SELECT concat(`Locality`.`locality`,"
- ", region) FROM regions where id = `Locality`.`region_id`) AS `Locality__fullname`
FROM `realestate`.`properties` AS `Property` LEFT JOIN `realestate`.`categories` AS
`Category` ON (`Property`.`category_id` = `Category`.`id`) LEFT JOIN
`realestate`.`conditions` AS `Condition` ON (`Property`.`condition_id` =
`Condition`.`id`) LEFT JOIN `realestate`.`service_types` AS `ServiceType` ON
(`Property`.`service_type_id` = `ServiceType`.`id`) LEFT JOIN
`realestate`.`localities` AS `Locality` ON (`Property`.`locality_id` =
`Locality`.`id`)
WHERE `Property`.`price` BETWEEN 0 AND 99999999 AND
`FeaturesProperty`.`feature_id` = 3 AND `Property`.`viewable` = 1 LIMIT 15
What I need is
SELECT `Property`.`id`, `Property`.`address1`, `Property`.`address2`,
`Property`.`area`, `Property`.`category_id`, `Property`.`condition_id`,
`Property`.`contact_detail_id`, `Property`.`country_id`, `Property`.`description`,
`Property`.`length`, `Property`.`main_image_id`, `Property`.`price`,
`Property`.`service_type_id`, `Property`.`locality_id`, `Property`.`viewable`,
`Property`.`width`, `Property`.`bathroom_qty`, `Property`.`bedroom_qty`,
`Category`.`id`, `Category`.`category`, `Condition`.`id`, `Condition`.`condition`,
`ServiceType`.`id`, `ServiceType`.`service_type`, `Locality`.`id`,
`Locality`.`locality`, `Locality`.`region_id`, (SELECT concat(`Locality`.`locality`,"
- ", region) FROM regions where id = `Locality`.`region_id`) AS `Locality__fullname`
FROM `realestate`.`properties` AS `Property` LEFT JOIN `realestate`.`categories` AS
`Category` ON (`Property`.`category_id` = `Category`.`id`) LEFT JOIN
`realestate`.`conditions` AS `Condition` ON (`Property`.`condition_id` =
`Condition`.`id`) LEFT JOIN `realestate`.`service_types` AS `ServiceType` ON
(`Property`.`service_type_id` = `ServiceType`.`id`) LEFT JOIN
`realestate`.`localities` AS `Locality` ON (`Property`.`locality_id` =
`Locality`.`id`) left outer join `realestate`.`features_properties` AS `FeaturesProperty` ON
(`Property`.`id` = `FeaturesProperty`.`property_id`)
WHERE `Property`.`price` BETWEEN 0 AND 99999999 AND
`FeaturesProperty`.`feature_id` = 3 AND `Property`.`viewable` = 1 LIMIT 15
The most important part is
left outer join realestate
.features_properties
AS FeaturesProperty
ON
(Property
.id
= FeaturesProperty
.property_id
)
Also since it might help hereunder are the relations from property model
/**
* belongsTo associations
*/
public $belongsTo = array(
'Category' => array(
'className' => 'Category',
'foreignKey' => 'category_id'
),
'Condition' => array(
'className' => 'Condition',
'foreignKey' => 'condition_id'
),
'ContactDetail' => array(
'className' => 'ContactDetail',
'foreignKey' => 'contact_detail_id'
),
'ServiceType' => array(
'className' => 'ServiceType',
'foreignKey' => 'service_type_id'
),
'Country' => array(
'className' => 'Country',
'foreignKey' => 'country_id'
),
'Locality' => array(
'className' => 'Locality',
'foreignKey' => 'locality_id'
)
);
/**
* hasMany associations
*/
public $hasMany = array(
'Image' => array(
'className' => 'Image',
'foreignKey' => 'property_id',
'dependent' => false,
),
'DetailsProperty' => array(
'className' => 'DetailsProperty',
'foreignKey' => 'property_id'
),
'FeaturesProperty' => array(
'className' => 'FeaturesProperty',
'foreignKey' => 'property_id'
)
);
public $hasAndBelongsToMany = array(
'Detail' =>
array(
'className' => 'Detail',
'joinTable' => 'details_properties',
'foreignKey' => 'property_id',
'associationForeignKey' => 'detail_id',
),
'Feature' =>
array(
'className' => 'Feature',
'joinTable' => 'features_properties',
'foreignKey' => 'property_id',
'associationForeignKey' => 'feature_id',
)
);