Search code examples
rubyrails-activerecordsequel

Does Sequel have anything like ActiveRecord's `merge` method?


Using ActiveRecord's merge method, if I have a scope on Author called name_like, I can use that to find books by author name using Book.joins(:author).merge(Author.name_like("lew"))

That produces this query (for one version of name_like):

SELECT "books".* FROM "books" 
INNER JOIN "authors" ON "authors"."id" = "books"."author_id"
WHERE (concat(first_name, ' ', last_name) ILIKE '%lew%')

Does Sequel have something equivilent to this? I don't see it in Sequel for ActiveRecord Users.


Solution

  • There isn't anything like merge. For a query like that in Sequel, you could do:

    Book.association_join(:author).
      where(Sequel.join([:first_name, :last_name], ' ').ilike('%lew%'))