madeintandem / hstore_accessor

Adds typed hstore-backed field support to ActiveRecord models.
MIT License
242 stars 47 forks source link

Added default values #31

Closed yawn closed 9 years ago

yawn commented 9 years ago

Solves #7 and could easily be extend to solve #20 (making #30 obsolete perhaps, didn't look too close).

Currently I treat the default value as transient / sth. that is evaluated once (and not cached) in the getter. So before merging we should agree on whether

  1. the value should get cached (currently: not)
  2. present? etc. should return always true for default value (currently: not)
thegrubbsian commented 9 years ago

I went ahead and merged this but then reverted it. My reservation is around what happens when there's a complex value (hash or array) as the value returned from the default block. Knowing that PG will just convert the value to a string we could get weird behavior, returning a hash from the default block for example, once persisted, would just get to_s'd and then when we pull it back from the database it would just be a weird string.

The only things I can think to do would be to force only simple types or specify deserialization types explicitly. Neither seem very use friendly.