I can see the exact result as expected.
I see the car details,
all the images are included,
I can see the listingfeatures as well (I am well aware I don't need to see this)
BUT I can not the the features ... the object is present but there is no data in it.
I have looked at the query log and the query seems correct:
SELECT `features`.* FROM `features` INNER JOIN `listingfeatures` ON(`features`.id = `listingfeatures`.feature_id) WHERE `listing_id` IN('124')
If I run the query in mysql I do get the features back.
I think this is a bug in phpactiverecord or am I missing something or do you have any suggestions?
Subject: Bug the through association?
Hi
I can't seem to get the right data when using the through associations and I am convinced I have done it correctly.
A little background about the app I am building it's all about listing cars on a websites
A listing is a car,
A listing may have many images
A listing may have many features through the listingfeatures table
I have the following tables:
listings
-id
-name
listingimages
-id
-listing_id
-image_name
listingfeatures
-id
-listing_id
-feature_id
features
-id
-name
My Models associations setup are as follows"
Listing
static $has_many = array(
array('listingimages', 'order' => 'weight asc'),
array('listingfeatures'),
array('features', 'through' => 'listingfeatures')
);
Listingimage
static $belongs_to = array(
array('listing'),
);
Listingfeature
static $belongs_to = array(
array('listing'),
array('feature'),
);
Feature
static $has_many = array(
array('listingfeatures'),
array('listings', 'through' => 'listingfeatures'),
);
Then calling
$car = Listing::find('all', array('conditions' => array('id = 124'), 'include' => array('listingimages', 'listingfeatures', 'features') ) );
print_r($car);
I can see the exact result as expected.
I see the car details,
all the images are included,
I can see the listingfeatures as well (I am well aware I don't need to see this)
BUT I can not the the features ... the object is present but there is no data in it.
I have looked at the query log and the query seems correct:
SELECT `features`.* FROM `features` INNER JOIN `listingfeatures` ON(`features`.id = `listingfeatures`.feature_id) WHERE `listing_id` IN('124')
If I run the query in mysql I do get the features back.
I think this is a bug in phpactiverecord or am I missing something or do you have any suggestions?