This project is archived and is in readonly mode.
ActiveRecord should favor ActiveModel API
-
David Chelimsky
Note that
new_record?is not removed by this change (that would not be so good for the myriad extensions rely on it). The change is that ActiveRecord usespersisted?internally andnew_record?depends on the state ofpersisted?, rather than the other way 'round. -
José Valim
- Importance changed from to Low
David, I was the person who added the mentioned failing test and the reason is here (after some git blame):
#4296 dom_id returns incorrect value for destroyed records
Notice though that #to_key implementation does not care if the record was persisted or not:
https://github.com/rails/rails/blob/master/activemodel/lib/active_m...
That said, the test is valid but we could probably change the current to_key implementation in AR to the following:
def to_key key = send(self.class.primary_key) [key] if key endSo what do you think?
-
David Chelimsky
That seems fine to me, as long as
persisted?returns false if it's been destroyed. Do you want me to make that change in my patch? Or merge what I've got and update it after? -
David Chelimsky
FYI - the updated patch is rebased off a more recent master. Everything is passing now for me.
-
José Valim
Yes, persisted? should return false if the object is destroyed. After a quick glance, the patch looks fine to me!
-
Repository
- State changed from new to committed
(from [1f06652a57e727700c3a673dc1f86e3b1e07ce1f]) use persisted? instead of new_record? wherever possible
- persisted? is the API defined in ActiveModel
- makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord
[#5927 ActiveRecord should favor ActiveModel API state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/1f06652a57e727700c3a673dc1f86... -
Repository
(from [f1c13b0dd7b22b5f6289ca1a09f1d7a8c7c8584b]) use persisted? instead of new_record? wherever possible
- persisted? is the API defined in ActiveModel
- makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord
[#5927 ActiveRecord should favor ActiveModel API state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/f1c13b0dd7b22b5f6289ca1a09f1d...