soveran / ohm

Object-Hash Mapping for Redis
http://ohm.keyvalue.org
MIT License
1.4k stars 167 forks source link

Ignoring Redis fields that are missing in the model? #234

Open rgaufman opened 6 years ago

rgaufman commented 6 years ago

When I change my model, any fields that are still present in Redis cause a NoMethodError, e.g.

> Device.all.entries[0]
Traceback (most recent call last):
        2: from (irb):5
        1: from (irb):5:in `entries'
NoMethodError (undefined method `created_at=' for #<Device:0x0000000004c48278 @attributes={}, @_memo={}>)

Is there any way to get Ohm to ignore any fields from Redis that are not in the model? - or is there some other recommended strategy to handle this?

soveran commented 6 years ago

@rgaufman I will work on this. I did some experiments in the past and it's true that those cases should be handled in a better way.

carina-akaia commented 6 years ago

irb(main):012:0> Transaction[3].remove NoMethodError: undefined method 'timestamp=' for #<Transaction:0x0000561b588b76e8> I have the same problem when try to delete object with the attribute, deleted from model before

pote commented 6 years ago

Maybe just having more explicit exceptions that suggest the standard solution to the problem would be enough?

@katecanaveral this happens because you'd have to set to nil the attribute in all objects before you remove attribute :timestamp from your code, since the Transaction#timestamp and Transaction#timestamp= methods are defined by Ohm when attribute is present.

If I'm not mistaken, the process would be:

1) Set all Transaction#timestamp to nil - with a migration-like script or manually. 2) Remove attribute :timestamp. 3) Deploy the new code.

carina-akaia commented 6 years ago

@pote thanks for the solution