I have three models:
- Country (id)
- Location (id, country_id)
- Objects (id, location_id)
I have defined relationships between them : locationid belongs to Location, countryid belongs to Country.
Now, when a user enters the country in a form, I want it to list all objects in that country (objects in all locations in that country). I tried it this way, according to http://docs.phalconphp.com/en/latest/reference/models.html#taking-advantage-of-relationships, but it's not good:
$country = Country::findFirst(array( "conditions" => "id = '$entered_country'" )); $locations = $country->location; $objects = Objects::find(array( "conditions" => "location_id IN ('$locations->id') " ));
First two lines are good, but the third one is wrong. Is there a better way to achieve this? Is my database ralational model ok ?