Ruby/Rails Collection to Collection

前端 未结 4 1696
天涯浪人
天涯浪人 2021-02-09 23:04

I have a two tables joined with a join table - this is just pseudo code:

Library
Book
LibraryBooks

What I need to do is if i have the id of a l

4条回答
  •  温柔的废话
    2021-02-09 23:21

    If you want a one-dimensional array of libraries returned, with duplicates removed.

    l.books.map{|b| b.libraries}.flatten.uniq
    

提交回复
热议问题