On 13 July 2010 06:03, Adrian Zatta <[email protected]> wrote:
> Hi everyone,
> 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.

You talked about required earlier, is that the same as prior?

Is there a good reason why you don't just put PriorKnowledge and
EnabledKnowledge in the same class and table with a boolean to
indicate which?

>
> 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.

I am obviously missing something, why can't you just say
@element.prior_knowledge
and
@element.enabled_logic

>
> 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);

Now you seem to have a 'knowledges' table which you have not mentioned before.

Colin

>
> 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.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to