diff --git a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php index 54850fa33b24..20b2b4f7b76f 100755 --- a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php @@ -316,7 +316,7 @@ protected function setForeignAttributesForCreate(Model $model) */ public function update(array $attributes) { - if ($this->related->usesTimestamps()) { + if ($this->related->usesTimestamps() && ! is_null($this->relatedUpdatedAt())) { $attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestampString(); } diff --git a/tests/Database/DatabaseEloquentHasManyTest.php b/tests/Database/DatabaseEloquentHasManyTest.php index 48fda761340a..038fe47b0c4b 100755 --- a/tests/Database/DatabaseEloquentHasManyTest.php +++ b/tests/Database/DatabaseEloquentHasManyTest.php @@ -173,6 +173,16 @@ public function testUpdateMethodUpdatesModelsWithTimestamps() $this->assertEquals('results', $relation->update(['foo' => 'bar'])); } + public function testUpdateMethodUpdatesModelsWithNullUpdatedAt() + { + $relation = $this->getRelation(); + $relation->getRelated()->shouldReceive('usesTimestamps')->once()->andReturn(true); + $relation->getRelated()->shouldReceive('getUpdatedAtColumn')->andReturn(null); + $relation->getQuery()->shouldReceive('update')->once()->with(['foo' => 'bar'])->andReturn('results'); + + $this->assertEquals('results', $relation->update(['foo' => 'bar'])); + } + public function testRelationIsProperlyInitialized() { $relation = $this->getRelation(); diff --git a/tests/Database/DatabaseEloquentHasOneTest.php b/tests/Database/DatabaseEloquentHasOneTest.php index 44910f720bbe..9e8f7ee4fce8 100755 --- a/tests/Database/DatabaseEloquentHasOneTest.php +++ b/tests/Database/DatabaseEloquentHasOneTest.php @@ -136,6 +136,16 @@ public function testUpdateMethodUpdatesModelsWithTimestamps() $this->assertEquals('results', $relation->update(['foo' => 'bar'])); } + public function testUpdateMethodUpdatesModelsWithNullUpdatedAt() + { + $relation = $this->getRelation(); + $relation->getRelated()->shouldReceive('usesTimestamps')->once()->andReturn(true); + $relation->getRelated()->shouldReceive('getUpdatedAtColumn')->andReturn(null); + $relation->getQuery()->shouldReceive('update')->once()->with(['foo' => 'bar'])->andReturn('results'); + + $this->assertEquals('results', $relation->update(['foo' => 'bar'])); + } + public function testRelationIsProperlyInitialized() { $relation = $this->getRelation();