Hi,
Let's say I have the following two models:
class Country extends Model {
public $id;
public $name;
public function initialize() {
$this->hasMany("id", "City", "country_id", [
'alias' => 'Cities'
]);
}
}
class City extends Model {
public $id;
public $country_id;
public $name;
public $isCapital;
public function initialize() {
$this->belongsTo("country_id", "Country", "id", [
'alias' => 'Country'
]);
}
}
And an Iceland object:
$Iceland = Country::findFirstByName('iceland');
Is there a way to get the capital of Iceland from the $Iceland object ?
I know of the filter()
method, which involves a user defined function, but I'd like to know if there's a more "compact" way. Something like:
// I know it's invalid
$IcelandCapital = $Iceland->Cities::findFirst(['isCapital' => 1]);
Thanks in advance.