laravel - Set hasOne relation to new instance of child model -


using laravel 4.2, how can set hasone relation on model instance of new model without touching database?

i want following, laravel treating instance property, not child relation.

class parentclass extends \eloquent {   public function child() {     return $this-hasone('childclass', 'child_id', 'parent_id');   } }  $parent = new parentclass(); $parent->child = new childclass(); 

to through problem, have created trait class added models allows me set relation. doing not automatically set parent/child relation values have careful manually before save/push.

trait modelsetrelationtrait {   public function setrelation($key, $model)   {     $this->relations[$key] = $model;   } }  class parentclass extends \eloquent {   use modelsetrelationtrait;   public function child() {     return $this-hasone('childclass', 'child_id', 'parent_id');   } } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -