public __construct ( |
||
$parentModel | The data model we are attached to | |
$foreignModelName | string | The name of the foreign key's model in the format "modelName@com_something" |
$localKey | string | The local table key for this relation |
$foreignKey | string | The foreign key for this relation |
$pivotTable | string | For many-to-many relations, the pivot (glue) table |
$pivotLocalKey | string | For many-to-many relations, the pivot table's column storing the local key |
$pivotForeignKey | string | For many-to-many relations, the pivot table's column storing the foreign key |
public function __construct(DataModel $parentModel, $foreignModelName, $localKey = null, $foreignKey = null, $pivotTable = null, $pivotLocalKey = null, $pivotForeignKey = null)
{
$this->parentModel = $parentModel;
$this->foreignModelClass = $foreignModelName;
$this->localKey = $localKey;
$this->foreignKey = $foreignKey;
$this->pivotTable = $pivotTable;
$this->pivotLocalKey = $pivotLocalKey;
$this->pivotForeignKey = $pivotForeignKey;
$this->container = $parentModel->getContainer();
$class = $foreignModelName;
if (strpos($class, '@') === false) {
$this->foreignModelComponent = null;
$this->foreignModelName = $class;
} else {
$foreignParts = explode('@', $class, 2);
$this->foreignModelComponent = $foreignParts[1];
$this->foreignModelName = $foreignParts[0];
}
}
/** * Public constructor. Initialises the relation. * * @param DataModel $parentModel The data model we are attached to * @param string $foreignModelName The name of the foreign key's model in the format "modelName@com_something" * @param string $localKey The local table key for this relation, default: parentModel's ID field name * @param string $foreignKey The foreign key for this relation, default: parentModel's ID field name * @param string $pivotTable IGNORED * @param string $pivotLocalKey IGNORED * @param string $pivotForeignKey IGNORED */ public function __construct(DataModel $parentModel, $foreignModelName, $localKey = null, $foreignKey = null, $pivotTable = null, $pivotLocalKey = null, $pivotForeignKey = null) { parent::__construct($parentModel, $foreignModelName, $localKey, $foreignKey, $pivotTable, $pivotLocalKey, $pivotForeignKey); if (empty($this->localKey)) { $this->localKey = $parentModel->getIdFieldName(); } if (empty($this->foreignKey)) { $this->foreignKey = $this->localKey; } }