symfony - Why is Doctrine joining this entity onto itself? (Not unique table/alias) -
i have entity named 'tile', manytomany relationship entity named 'coins'.
/** * @orm\manytomany(targetentity="coin") * @orm\jointable(name="coin", * joincolumns={@orm\joincolumn(name="tile_id", referencedcolumnname="tile_id")}, * inversejoincolumns={@orm\joincolumn(name="coin_id", referencedcolumnname="coin_id")} * ) **/ protected $coins;
i have page lists tiles , of associated coins. there can lot of coins , tiles on page , using lazy loading can put 100-300 database queries on single page. trying avoid using leftjoin.
public function getusertiles($id) { $qb = $this->createquerybuilder('b') ->select('b', 'z') ->leftjoin('b.coins', 'z') ->leftjoin('z.userinfo', 'u') ->add('where', "b.userid = ".$id." , b.status = 'completed'") ->add('orderby', "b.checkindate desc"); return $qb->getquery() ->getresult(); }
this gives me following error:
*[2/2] dbalexception: exception occurred while executing ' select t0_.tile_id tile_id0, t0_.quilt_id quilt_id1, t0_.user_id user_id2, t0_.comment comment3, t0_.checkout_date checkout_date4, t0_.checkin_date checkin_date5, t0_.x x6, t0_.y y7, t0_.status status8, t0_.completed_neighbors completed_neighbors9, t0_.required_completed_neighbors required_completed_neighbors10, t0_.visible visible11, t0_.visible_date visible_date12, t0_.count_towards_coins count_towards_coins13, c1_.coin_id coin_id14, c1_.user_id user_id15, c1_.tile_id tile_id16, c1_.comment comment17, c1_.date_given date_given18, c1_.status status19, c1_.origin origin20, t0_.quilt_id quilt_id21, t0_.user_id user_id22, c1_.tile_id tile_id23, c1_.user_id user_id24 tile t0_ **left join coin *c1_* on t0_.tile_id = c1_.tile_id left join coin *c1_* on c1_.coin_id = c1_.coin_id** left join user_info u2_ on c1_.user_id = u2_.user_id t0_.user_id = 14 , t0_.status = 'completed' order t0_.checkin_date desc': sqlstate[42000]: syntax error or access violation: 1066 not unique table/alias: 'c1_'*
as can see, trying join coin table twice, using same alias. doing wrong?
try:
$this->createquerybuilder('b') ->select('b') ->addselect('z') ->leftjoin('b.coins', 'z') ->leftjoin('z.userinfo', 'u') ->where("b.userid = :id , b.status = 'completed'") ->orderby('b.checkindate', 'desc') ->setparameter('id', $id) ->getquery('b.checkindate desc') ->getsingleresult();
Comments
Post a Comment