Skip to content

Commit

Permalink
Make #update_attributes behavior identical to #update (#98)
Browse files Browse the repository at this point in the history
Another choice of implemention is like this:

```
@model.class.find_by(:"#{primary_key}" =>
@model.send(:"#{primary_key}")).update(attrs)
```

but for some reasons I don't adopt it.
First it makes 2 queries instead of one.
Secondly it has potential risk to race conditions.
  • Loading branch information
ebihara99999 authored and Ch4s3 committed Dec 13, 2017
1 parent f8a7c94 commit be614ba
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sorcery/adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def update_attributes(attrs)
@model.send(:"#{name}=", value)
end
primary_key = @model.class.primary_key
@model.class.where(:"#{primary_key}" => @model.send(:"#{primary_key}")).update_all(attrs)
updated_count = @model.class.where(:"#{primary_key}" => @model.send(:"#{primary_key}")).update_all(attrs)
updated_count == 1
end

def save(options = {})
Expand Down

0 comments on commit be614ba

Please sign in to comment.