Skip to content

Model keepSnapshots(true) not respected when manually assigning data to a model instance #15808

Answered by zsilbi
richmilns asked this question in Q&A
Discussion options

You must be logged in to vote

This is unnecessary:

$target = $builder->getQuery()->execute()->getFirst();
$record = new Members($target->toArray());

If your query is correct, $target should be a Members object which can be updated right away.

$builder = $this->modelsManager
   ->createBuilder()
   ->columns('m.*')
   ->from(['m' => Members::class])
   ->andWhere('m.id = :id: AND m.user_id = :user_id:', [
   		'id' => $this->request->getQuery('id'),
		'user_id' => 1
   ])
   ->innerJoin(Users::class, 'u.id = m.user_id AND u.deleted = 0', 'u');

$target = $builder->getQuery()->execute()->getFirst();
$target->title = $this->request->getPost('title');
$target->update();

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@richmilns
Comment options

@quasipickle
Comment options

@richmilns
Comment options

Answer selected by richmilns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants