It looks like you're new here. If you want to get involved, click one of these buttons!
public $has_many = array(
'authorities' => array(
// this model has many 'authorities'
'model' => array('app' => 'authorities_model'),
// the lookup table
'relationships_model' => 'authority_installation_model',
// the foreign key of the 'has many' table in lookup table
'foreign_key' => 'authority_id',
// this table's primary key in the lookup table
'candidate_key' => 'installation_id'
)
Comments
SELECT `authority_installation`.* FROM `authority_installation` WHERE `candidate_table` = 'installations' AND `foreign_table` = 'authorities' AND `authority_installation`.`installation_id` = '65'
My lookup table doesn't have foreign_table or candidate_table columns. When I add them, naturally, there's no problem
/** * Returns a belongsToMany relationship object using a shared table. * Handy if you don't like creating pivot tables for every belongsToMay relationship. * * @return Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function sharedRelationship($model, $tableInfo = null) { if (is_string($model)) { $foreignModel = $model; $model = new $model; } else { $foreignModel = get_class($model); } $defaultTableInfo = [ 'table' => (defined('static::SHARED_RELATIONSHIPS_TABLE') ? static::SHARED_RELATIONSHIPS_TABLE : 'fuel_relationships'), 'key_column' => 'key', 'table_column' => 'table', 'foreign_key_column' => 'foreign_key', 'foreign_table_column' => 'foreign_table' ]; $tableInfo = (empty($tableInfo)) ? $defaultTableInfo : array_merge($defaultTableInfo, $tableInfo); $belongsToMany = $this->belongsToMany($foreignModel, $tableInfo['table'], $tableInfo['key_column'], $tableInfo['foreign_key_column']) ->wherePivot('table', $this->getTable()) ->wherePivot('foreign_table', $model->getTable()) ; return $belongsToMany; }