I’ve a component model that has_many :framework. But the :framework don’t belongs_to :component, because a framework could belong to lots of components.
I’ve a controller that returns a json with the frameworks of a concret component:
def getFrameworks
@component = Component.find(params[:component_id])
respond_to do |format|
format.html { redirect_to components_url }
format.json { render json: @component.frameworks, location: @component }
end
end
But it gives me the following error:
SQLite3::SQLException: no such column: frameworks.component_id: SELECT "frameworks".* FROM "frameworks" WHERE "frameworks"."component_id" = 298
Am I defining wrong the model? What’s wrong?
A
has_manyneeds abelongs_toon the related model, for your caseI believe you want to use the
has_and_belongs_to_manyrelation, see the docHere is an example of the migration you will need :