real array via has_many

17 views
Skip to first unread message

Zdravko Balorda

unread,
May 27, 2016, 9:21:11 AM5/27/16
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

Norbert Melzer

unread,
May 27, 2016, 9:34:35 AM5/27/16
to rubyonra...@googlegroups.com

Has many does not resemble an array but a set.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c27b4c1b1fcb46b05da40a52d820cb65%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Zdravko Balorda

unread,
May 27, 2016, 9:53:35 AM5/27/16
to rubyonra...@googlegroups.com
Yes. So how one can handle arrays properly?

Norbert Melzer

unread,
May 27, 2016, 10:57:46 AM5/27/16
to rubyonra...@googlegroups.com

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.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Colin Law

unread,
May 28, 2016, 3:40:35 AM5/28/16
to Ruby on Rails: Talk
On 27 May 2016 at 14:53, Zdravko Balorda <li...@ruby-forum.com> 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

Zdravko Balorda

unread,
May 28, 2016, 5:18:02 AM5/28/16
to rubyonra...@googlegroups.com
I think I found a solution: act_as_list.
Sometimes we just need persistant storage.

Thanks.
Reply all
Reply to author
Forward
0 new messages