I'm trying to create a query to show every content of a section in my CMS.
The relation is one to many, one content has many sections.
Now I create a section controller and in the show method i receive the params[:id] of a section.
I must select all the contents where the content.section_ids array include my params[:id]
I know how to create the inverse query (where ID in array), but I cannot find a solution for this.
My query is:
@contents = Content.published.recent.where("#{params[:id]} IN (?)", ...)
Update
This is the relation.
I must select all the contents where the section is == to the section ID passed in my params.
class Content < ActiveRecord::Base
has_many :sections, as: :sectionable
end
class Section< ActiveRecord::Base
belongs_to :sectionable, polymorphic: true
end