Hi all, I’m a little bit stuck on this one. I really like the active relations, once they are set up, they can really simplify your work, but perhaps I can’t make them work for this case, let me explain.
I have two tables CatalogItem and ProfileItems these two tables relate this way, other fields are removed.
CatalogItem has various fields but for this example we only need to consider the id field which is the primaryKey.
Users can set up profiles, the CatalogItem(s) are either a job requirement or a job offering (a service).
ProfileItems is essentially a join table. Fields of interest in ProfileItems are type and item. Item points directly to the CatalogItem->id and ‘type’ can be either 1 or 2 depending on if the service is required or offered.
CatalogItem ProfileItems
id <--- item
type either 1 or 2
configuring my relations in CatalogItem I can get all of the profiles that point to the catalog item specified.
'profileItems'=>array(self::HAS_MANY,'ProfileItems','item')
// or for clarity
'profileItems'=>array(self::HAS_MANY,'ProfileItems',array('item'=>'id')),
So this works
$profilesPointingToCatalogItem = CatalogItem::model()->findByPk($id)->profileItems;
But how can I filter for the ‘type’ field? for example I want to find all of the profiles that are service providers (type = 1) that offer a particular CatalogItem?
Is this possible in a relation?
Thanks,
doodle