her icon indicating copy to clipboard operation
her copied to clipboard

primary_key and dirty tracking

Open zacharywelch opened this issue 7 years ago • 0 comments

Her doesn't setup dirty tracking on id or primary_key when a new model's initialized. This impacts the behavior of persisted? and new_record?

Existing behavior

class User
  include Her::Model
end

user = User.new(id: 5) #=> #<User(users/5) id=5>
user.new_record? #=> false
user.persisted? #=> true
user.changes #=> {}

Expected behavior

class User
  include Her::Model
end

user = User.new(id: 5) #=> #<User(users/5) id=5>
user.new_record? #=> true
user.persisted? #=> false
user.changes #=> {"id"=>[nil, 5]}

See #298 for more background.

We may need to track an instance variable of @new_record similar to AR

zacharywelch avatar Apr 13 '18 13:04 zacharywelch