Please help me to avoid this syntax error
I want to select first category with its children.
@categories=Category.where(categories: {id:[1]} && categories: {parent_id:[1]})
Please help me to avoid this syntax error
I want to select first category with its children.
@categories=Category.where(categories: {id:[1]} && categories: {parent_id:[1]})
Why not just do this?
@categories = Category.where(id: [1], parent_id: [1])
This will give you all the categories with id = 1
AND parent_id = 1
.
Note that, you don't need the []
unless you want to include array of ids or parents ids. If you want for one id and one parent id only, you can just do this:
@categories = Category.where(id: 1, parent_id: 1)
Assuming you want to find the Category record with id=1 and parent_id=1 the query should be:
@category = Category.where(id: 1, parent_id: 1).first