You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to set up a 'has-many-pivot' relationship where the pivot table is mapping a relationship between records in the same table.
In my case, I have a location_model on top of table 'locations' and tried to define the following relationship in my location_model:
$this->has_many_pivot['related'] = array(
'foreign_model'=>'location_model',
'pivot_table'=>'related_locations',
'local_key'=>'id',
'pivot_local_key'=>'location_id',
'pivot_foreign_key'=>'related_location_id',
'foreign_key'=>'id'
);
A call to
$record = $this->location_mode->with_related()->get(1);
results in the following SQL that fails with SQL Error 1066: Not unique table/alias: 'locations'
SELECT locations.id, related_locations.location_id
FROM locations
LEFT JOIN related_locations ON locations.id = related_locations.related_location_id
LEFT JOIN locations ON related_locations.location_id = locations.id
WHERE related_locations.location_id IN('1')
Is there currently a way to have MY_Model alias one (or both) of the tables?
The text was updated successfully, but these errors were encountered:
Is it possible to set up a 'has-many-pivot' relationship where the pivot table is mapping a relationship between records in the same table.
In my case, I have a location_model on top of table 'locations' and tried to define the following relationship in my location_model:
$this->has_many_pivot['related'] = array(
'foreign_model'=>'location_model',
'pivot_table'=>'related_locations',
'local_key'=>'id',
'pivot_local_key'=>'location_id',
'pivot_foreign_key'=>'related_location_id',
'foreign_key'=>'id'
);
A call to
$record = $this->location_mode->with_related()->get(1);
results in the following SQL that fails with SQL Error 1066: Not unique table/alias: 'locations'
SELECT
locations
.id
,related_locations
.location_id
FROM
locations
LEFT JOIN
related_locations
ONlocations
.id
=related_locations
.related_location_id
LEFT JOIN
locations
ONrelated_locations
.location_id
=locations
.id
WHERE
related_locations
.location_id
IN('1')Is there currently a way to have MY_Model alias one (or both) of the tables?
The text was updated successfully, but these errors were encountered: