Real array via has_many

The way to implement arrays in ActiveRecord is via has_many.
But, normally Ruby arrays keep the order of elements, while has_many do
not.
This is not just a matter of “order by” clause.
At every update one needs to index database table rows properly, so that
“order by” would work.

Thanks in advance.

Has many does not resemble an array but a set.

Zdravko B. [email protected] schrieb am Fr., 27. Mai 2016
15:20:

Yes. So how one can handle arrays properly?

You have to add an index column and use order by. SQL as a standard does
not guarantee any ordering unless you enforce it, so any implementation
can
return elements in the order that is most efficient.

Zdravko B. [email protected] schrieb am Fr., 27. Mai 2016
15:53:

I think I found a solution: act_as_list.
Sometimes we just need persistant storage.

Thanks.

On 27 May 2016 at 14:53, Zdravko B. [email protected] wrote:

Yes. So how one can handle arrays properly?

Can you give us more information on what is in your array and for what
reason they are sorted? Someone may be able to suggest a better
solution to the problem.

Please quote the relevant parts of previous message when posting, this
is a mailing list not a forum (though you may be accessing it via a
forum-like interface) so it is not always obvious which message you
are replying to. Thanks.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs