I\'m trying to write LIKE query.
I read that pure string quires aren\'t safe, however I couldn\'t find any documentation that explain how to write safe LIKE Hash Que
In case if anyone performing search query on nested association try this:
Model.joins(:association).where(
Association.arel_table[:attr1].matches("%#{query}%")
)
For multiple attributes try this:
Model.joins(:association).where(
AssociatedModelName.arel_table[:attr1].matches("%#{query}%")
.or(AssociatedModelName.arel_table[:attr2].matches("%#{query}%"))
.or(AssociatedModelName.arel_table[:attr3].matches("%#{query}%"))
)
Don't forget to replace AssociatedModelName with your model name