public function __construct($options = []) { parent::__construct($options); if (!$this->class_name) { $this->setInferredClassName(); } //infer from class_name if (!$this->foreign_key) { $this->foreign_key = [Inflector::instance()->keyify($this->class_name)]; } }
public function createAssociation(Model $model, $attributes = [], $guard_attributes = true) { $relationship_attributes = $this->getForeignKeyForNewAssociation($model); if ($guard_attributes) { // First build the record with just our relationship attributes (unguarded) $record = parent::buildAssociation($model, $relationship_attributes, false); // Then, set our normal attributes (using guarding) $record->setAttributes($attributes); // Save our model, as a "create" instantly saves after building $record->save(); } else { // Merge our attributes $attributes = \array_merge($relationship_attributes, $attributes); // First build the record with just our relationship attributes (unguarded) $record = parent::createAssociation($model, $attributes, $guard_attributes); } return $record; }