Пример #1
0
 public function create_association(Model $model, $attributes = array())
 {
     $attributes = $this->inject_foreign_key_for_new_association($model, $attributes);
     return parent::create_association($model, $attributes);
 }
Пример #2
0
 public function create_association(Model $model, $attributes = array(), $guard_attributes = true)
 {
     $relationship_attributes = $this->get_foreign_key_for_new_association($model);
     if ($guard_attributes) {
         // First build the record with just our relationship attributes (unguarded)
         $record = parent::build_association($model, $relationship_attributes, false);
         // Then, set our normal attributes (using guarding)
         $record->set_attributes($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::create_association($model, $attributes, $guard_attributes);
     }
     return $record;
 }