madeintandem / hstore_accessor

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

Adding to hstore Array does not work #22

Closed resistorsoftware closed 10 years ago

resistorsoftware commented 10 years ago

Hi,

In my model Order I have an hstore setup as:

hstore_accessor :refund, refunds: :array

I can set an array with no trouble:

order.refunds = [123456]
=> [123456]

But I cannot push new values to an array

order.refunds.push 44332211
=> [123456,44332211]
order.refunds
=> [123456]

Same with the << syntax

Am I missing something basic here? If the class of the column is Array, I think .push and << should work... otherwise this is not too terribly useful? I would need to save the old array to some temp variable, push to that, and then set the new array?

Anyone else see this behaviour with arrays?

devmyndstatus commented 10 years ago

Unfortunately I think this is somewhat unavoidable and works the same way array columns (not hstore backed, but actually Postgres array columns) work with ActiveRecord.

Thanks, //JC Grubbs | DevMynd (717) 347-8227 http://devmynd.com

On Mon, Apr 14, 2014 at 2:41 PM, David Lazar notifications@github.comwrote:

Hi,

In my model Order I have an hstore setup as:

hstore_accessor :refund, refunds: :array

I can set an array with no trouble:

order.refunds = [123456] => [123456]

But I cannot push new values to an array

order.refunds.push 44332211 => [123456,44332211] order.refunds => [123456]

Same with the << syntax

Am I missing something basic here? If the class of the column is Array, I think .push and << should work... otherwise this is not too terribly useful? I would need to save the old array to some temp variable, push to that, and then set the new array?

Anyone else see this behaviour with arrays?

— Reply to this email directly or view it on GitHubhttps://github.com/devmynd/hstore_accessor/issues/22 .

resistorsoftware commented 10 years ago

Ok.. no biggy.. through me for a bit, but after going through the source code, and seeing no implementation of Enumerable, I get it... I will code accordingly... thanks!