Reputation: 3462
i'm currently building a calendar which displays events each event belongsto an eventlocation with a foreign key of event_location_id each eventlocation hasmany events with a foreign id of event_location_id. Which gets the name of the event_location based on its id. Now im adding side deals and i can only get the event_location_id and not the name can anyone help? or possibly give a better explanation of what foreign id are for and do.
i just need to know how to get an event by it's id and then get the event_location_id from the event and then get the name from event_locations table according to the event_location_id.
Upvotes: 0
Views: 712
Reputation: 3252
I would suggest using the containable behaviour. It will manage the recursion for you. Containable will be good enough for most purposes, unless the query is very complicated.
Upvotes: 1
Reputation: 521995
If you have set up your associations properly it should be as easy as:
$this->Event->recursive = 2;
$event = $this->Event->read(null, $id);
debug($event);
Cake automatically fetches data for associated models.
Upvotes: 0