On Tuesday, March 7, 2017 at 4:51:55 PM UTC-8, Federico Saravia wrote:
>
> Hi everyone,
>
> I have a simple problem for which I can't find a good solution. I have two 
> Sequel::Models models that have a many_to_many relationship between them:
>
> class Author < Sequel::Model
>   many_to_many :posts
> end
>
> class Post < Sequel::Model
> end
>
> I need to fetch Author#posts in the same order that those posts were added 
> to the association.
>
> This means that if I have this:
>
> author = Author.create
>
> post_1 = Post.create
> post_2 = Post.create
>
> author.add_post << post_2
> author.add_post << post_1
>
> Then calling author.posts returns that array in that exact same order.
>
> I can add any column I want to the join table but I don't know how to tell 
> Sequel to sort the elements based on that column.
>
> Thanks!
>

  Author.many_to_many :posts, :order=>Sequel[:authors_posts][:sort_column]

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to