rummage_ecto icon indicating copy to clipboard operation
rummage_ecto copied to clipboard

Search Schema by field and field in the assoc

Open duartepbrandao opened this issue 6 years ago • 4 comments

Hello.

Is it possible to search for both a field and a field from the assoc of the schema. For example, using the phoenix_example(v2) project, searching for all the products where the category_name = "fic" and the product_name = "the" ?

I am sending these rummage_params:

params: %{
  paginate: %{page: 1, per_page: 5},
  search: %{
    category_name: "fic",
    internal_code: %{search_term: "", search_type: :ilike},
    name: %{search_term: "the", search_type: :ilike}
  }
}

but the query it creates its this one (columns removed for readability) :

SELECT * FROM (SELECT * FROM (SELECT * FROM "products" AS p0) AS s0
WHERE (s0."internal_code" ILIKE $1)) AS s0 WHERE (s0."name" ILIKE $2) 
LIMIT $3 OFFSET $4 ["%%", "%the%", 5, 0]

If this is not possible, can you point me in the direction for doing a PR for this functionality.

Thanks

duartepbrandao avatar Oct 12 '18 09:10 duartepbrandao

Hi @duartepbrandao, At this point, no. There will need to be a bigger change in rummage_ecto for this to work. The search hook needs to accept inputs in a different format. I think enough people have requested this feature, so I think maybe we should add this to 2.0 release!

What do you think @ericsullivan?

thebugcatcher avatar Oct 12 '18 12:10 thebugcatcher

I think it's important enough to get it into the 2.0 release

ericsullivan avatar Oct 12 '18 13:10 ericsullivan

Cool! I will add it to the queue then!

thebugcatcher avatar Oct 12 '18 15:10 thebugcatcher

I have actually got it working tinkering with the rummage_scope and using the custom search.

duartepbrandao avatar Oct 15 '18 11:10 duartepbrandao