Hi,
Phalcon ORM's magic getters don't always return the results I expect. See these examples:
Countries Cities
+----+--------+ +----+------------+------------+------------+
| id | name | | id | name | country_id | is_capital |
+----+--------+ +----+------------+------------+------------+
| 1 | UK | | 1 | London | 1 | 1 |
+----+--------+ | 2 | Manchester | 1 | 0 |
| 3 | Liverpool | 1 | 0 |
+----+------------+------------+------------+
class Countries extends Model {
public $id;
public $name;
public function initialize() {
$this->hasMany('id', 'Cities', 'country_id', [
'alias' => 'Cities'
]);
}
}
class Cities extends Model {
public $id;
public $name;
public $country_id;
public $is_capital;
public function initialize() {
$this->belongsTo('country_id', 'Countries', 'id', [
'alias' => 'Country'
]);
}
}
$uk = Countries::findFirstByName("UK");
$r1 = $uk->getCities("is_capital = 1");
$r2 = $uk->getCities(['is_capital' => 1]);
// $r1 expectingly returns "London"
// $r2 surprisingly returns "London Manchester Liverpool"
$r3 = $uk->getCities("is_capital = 0");
$r4 = $uk->getCities(['is_capital' => 0]);
// $r3 expectingly returns "Manchester Liverpool"
// $r4 surprisingly returns "London Manchester Liverpool"
$r5 = $uk->getCities("is_capital = 'blabla'");
$r6 = $uk->getCities(['is_capital' => 'blabla']);
// $r5 surprisingly returns "Manchester Liverpool"
// $r6 surprisingly returns "London Manchester Liverpool"
Should I conclude that:
- passing an array of parameters to a magic getter is not reliable? ($r2, $r4, $r6)
- and even when passing in a string, I can sometimes get surprises? ($r5)
Or am I missing something?
Thanks!