Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated_at column updated even if null if updated by relation #23741

Closed
neodc opened this issue Mar 29, 2018 · 0 comments
Closed

updated_at column updated even if null if updated by relation #23741

neodc opened this issue Mar 29, 2018 · 0 comments

Comments

@neodc
Copy link

neodc commented Mar 29, 2018

  • Laravel Version: 5.6.3
  • PHP Version: 7.2.3
  • Database Driver & Version: N/A

Description:

In my system I have tables with an created_at column but no updated_at column so I created my models with $timestamps = true and UPDATED_AT = null.

It works when I do direct action on the model but when I try to do a bulk update by a relation the relation try to set an empty column to the current time.

For me it's a bug in IlluminateDatabaseEloquentRelationsHasOneOrMany::update, it add the updated_at attribute even if it's null.

Steps To Reproduce:

  1. Create a model with UPDATED_AT = null
  2. Use this model in an hasMany relation
  3. Try to update the related model by the relation
class Bug extends Eloquent
{
	const UPDATED_AT = null;
}

class Foo extends Eloquent
{
	public function bugs()
	{
		return $this->hasMany(Bug::class);
	}
}

$foo = // An instance of Foo
$foo->bugs()->update([
	'test' => 'bar',
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant