I have three models:
- Country (id)
- Location (id, country_id)
- Objects (id, location_id)
I have defined relationships between them : location_id belongs to Location, country_id 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 https://docs.phalcon.io/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 ?
Thanks