I have the following basic rules:
Subject has many elements
Element has many subjects
Element has many knowledges which are either enabled or required
Element has many skills which are either enabled or required
I have designed the schema to have 6 tables, Subjects, Elements,
PriorKnowledge, PriorSkills, EnabledKnowledge and EnabledSkills.
Now to my problem. I am trying to build a page that will display all
this information. It will display a subject and all its elements, and
all of the elements prior and enabled, knowledges and skills.
The thought that I had was to use has_many :through relationships, but I
don't know how to handle both prior and enabled cases.
My next thought was to use a sql query to select the knowledge and skill
elements required and save them as class variables in elements. However
I don't know how to get the ID of the element i am working with.
This is the SQL query that does the job:
select description from knowledges where id in (select
knowledges_id from prior_knowledges where elements_id = 1);
I had this line in the element.rb file:
@@pk = Knowlegde.find_by_sql("select description from knowledges
where id in (select knowledges_id from prior_knowledges where
elements_id = " + id.to_s + ");")
But i kept getting a empty array but executing the same command in SQL
works, and executing the command manually in the console also works.