/** * @param Model $localModel * @param string $localKey identifying key on local model * @param string $foreignModel foreign model class * @param string $foreignKey identifying key on foreign model */ public function __construct(Model $localModel, $localKey, $foreignModel, $foreignKey) { // the default foreign key would look like // `user_id` for a model named User if (!$foreignKey) { $inflector = Inflector::get(); $foreignKey = strtolower($inflector->underscore($localModel::modelName())) . '_id'; } if (!$localKey) { $localKey = Model::DEFAULT_ID_PROPERTY; } parent::__construct($localModel, $localKey, $foreignModel, $foreignKey); }
/** * @param Model $localModel * @param string $localKey identifying key on local model * @param string $tablename pivot table name * @param string $foreignModel foreign model class * @param string $foreignKey identifying key on foreign model */ public function __construct(Model $localModel, $localKey, $tablename, $foreignModel, $foreignKey) { // the default local key would look like `user_id` // for a model named User if (!$localKey) { $inflector = Inflector::get(); $localKey = strtolower($inflector->underscore($foreignModel::modelName())) . '_id'; } if (!$foreignKey) { $foreignKey = Model::DEFAULT_ID_PROPERTY; } // the default pivot table name looks like // RoleUser for models named Role and User. // the tablename is built from the model names // in alphabetic order. if (!$tablename) { $names = [$localModel::modelName(), $foreignModel::modelName()]; sort($names); $tablename = implode($names); } $this->tablename = $tablename; parent::__construct($localModel, $localKey, $foreignModel, $foreignKey); }