0

I have a News Model which has polymorphic association with ContentRoles

I want to query news on created_at such that it fetches all the news greater than given timestamp

my query currently looks something like this

 @news = News.includes(:content_roles).where("created_at >= ?",params[:created_at] ,content_roles: {role_id: @role,content_type: "news"})

which is incorrect as it expects only one parameter for the prepared statement.

how do I query on news created_at with conditions ?

level0
  • 323
  • 1
  • 3
  • 13

1 Answers1

0

You can call where several times, and they will be chained with an AND:

@news = News.includes(:content_roles).where("created_at >= ?",params[:created_at]).where(content_roles: {role_id: @role,content_type: "news"})
Fer
  • 3,247
  • 1
  • 22
  • 33