Hi all,
A basic question I’m sure, but after exploring many to many relationships all day my head is total mush.
I’ve used the behaviors to easily add and remove relations using a join table. Basically I have the following
Table: Resource
-
id (PK)
-
name
Table: Service
-
id (PK)
-
name
Table Resource_Service_Mapping
-
resource_id (FK)
-
service_id (FK)
I can get data in this table, and it’s populating and it’s all awesome… Buttttt…
On each of the Resources form, and the Service form, I want to provide the ability to have a table of all the resources or services and allow users to have an ajax link to either create or remove that relationship.
ie. I want a form that looks like the following
Service1 Service2 Service3
Room 1 YES YES NO
Room 2 NO NO NO
Room 3 YES NO NO
ie. I want the full list of all the services on the resources (room) form, and then check the value of the mapping table when the value is toggled.
However I am not sure how to lookup the value from the relation table.
In relations on Services I have
‘resources’=>array(self::MANY_MANY, ‘Resource’, ‘services_resources_mapping(service_id, resource_id)’),
and in relations on Resources I have
‘services’=>array(self::MANY_MANY, ‘Resource’, ‘services_resources_mapping(resource_id, service_id)’),
However I just don’t know how to apply the filter to add a query on services? Any ideas… please??