File tree Expand file tree Collapse file tree
src/Illuminate/Database/Eloquent/Relations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -643,7 +643,7 @@ public function firstOrNew(array $attributes)
643643 {
644644 if (is_null ($ instance = $ this ->where ($ attributes )->first ()))
645645 {
646- $ instance = $ this ->related ->newInstance ();
646+ $ instance = $ this ->related ->newInstance ($ attributes );
647647 }
648648
649649 return $ instance ;
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ public function firstOrNew(array $attributes)
125125 {
126126 if (is_null ($ instance = $ this ->where ($ attributes )->first ()))
127127 {
128- $ instance = $ this ->related ->newInstance ();
128+ $ instance = $ this ->related ->newInstance ($ attributes );
129129
130130 // When saving a polymorphic relationship, we need to set not only the foreign
131131 // key, but also the foreign key type, which is typically the class name of
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ public function testFirstOrNewMethodReturnsNewModelWithMorphKeysSet()
110110 $ relation = $ this ->getOneRelation ();
111111 $ relation ->getQuery ()->shouldReceive ('where ' )->once ()->with (array ('foo ' ))->andReturn ($ relation ->getQuery ());
112112 $ relation ->getQuery ()->shouldReceive ('first ' )->once ()->with ()->andReturn (null );
113- $ relation ->getRelated ()->shouldReceive ('newInstance ' )->once ()->with ()->andReturn ($ model = m::mock ('Illuminate\Database\Eloquent\Model ' ));
113+ $ relation ->getRelated ()->shouldReceive ('newInstance ' )->once ()->with (array ( ' foo ' ) )->andReturn ($ model = m::mock ('Illuminate\Database\Eloquent\Model ' ));
114114 $ model ->shouldReceive ('setAttribute ' )->once ()->with ('morph_id ' , 1 );
115115 $ model ->shouldReceive ('setAttribute ' )->once ()->with ('morph_type ' , get_class ($ relation ->getParent ()));
116116 $ model ->shouldReceive ('save ' )->never ();
@@ -161,7 +161,7 @@ public function testUpdateOrCreateMethodCreatesNewMorphModel()
161161 $ relation = $ this ->getOneRelation ();
162162 $ relation ->getQuery ()->shouldReceive ('where ' )->once ()->with (array ('foo ' ))->andReturn ($ relation ->getQuery ());
163163 $ relation ->getQuery ()->shouldReceive ('first ' )->once ()->with ()->andReturn (null );
164- $ relation ->getRelated ()->shouldReceive ('newInstance ' )->once ()->with ()->andReturn ($ model = m::mock ('Illuminate\Database\Eloquent\Model ' ));
164+ $ relation ->getRelated ()->shouldReceive ('newInstance ' )->once ()->with (array ( ' foo ' ) )->andReturn ($ model = m::mock ('Illuminate\Database\Eloquent\Model ' ));
165165 $ model ->shouldReceive ('setAttribute ' )->once ()->with ('morph_id ' , 1 );
166166 $ model ->shouldReceive ('setAttribute ' )->once ()->with ('morph_type ' , get_class ($ relation ->getParent ()));
167167 $ model ->shouldReceive ('save ' )->once ()->andReturn (true );
You can’t perform that action at this time.
0 commit comments