Transitive left join results in repetitive records

Its 2.0.9.

There is an "accommodation". The "accommodation" has many "accommodatiobase". And "accommodationbase" has one "city"

So accommodation:

<?php
$this->hasMany('id', 'AccommodationBase', 'accommodation_id', array('alias' => 'AccommodationBase'));

Accommodationbase:

<?php
$this->belongsTo('city_id', 'City', 'id', array('alias' => 'City'));

and here is my builder:

<?php
$queryBuilder = (new \Phalcon\Mvc\Model\Query\Builder())->from('Accommodation')->where('Accommodation.id = 1');
$queryBuilder->leftJoin('AccommodationBase');
$queryBuilder->leftJoin('City');

the result [$queryBuilder->getQuery()->execute()] returns with tons of "accomodation", repetitve records. It should return one (check the where condition)

so in other words, joins:

A -> b

A -> c

workds but

A -> B -> C

results in many A (as much as C)



44.7k
edited Dec '15

Post the resultant SQL with getQuery()->getSql()["sql"]. You can build the PHQL yourself and if you are having issues with keys then you can disable implicit joining based on the defined relationships with the enable_implicit_joins option. Set it with the static method Model::setup or as an option in the query.