I''ve worked out I can do:
card.tests.find(Test.find_by_name(''testname'').id).passed?
but this will add another query for each test. Given that there will be
around 30-40 tests per card, surely this cannot be an adequate solution.
Anyone have any better ideas?
Thanks,
Sam
Sam Pohlenz wrote:
> Hi,
>
> I''m currently building a rails application to view the results of
a
> number of tests (boolean) on a number of cards. My current design uses
> three tables: cards, cards_tests and tests in a
> has_and_belongs_to_many relationship. Cards also has a type column and
> class inheritance is used to assign a type (if that''s relevant).
> Different types of cards will have a different set of tests, but cards
> of the same type will have the same tests.
> i.e.
>
> |cards| |cards_tests| |tests|
> ------- ------------- -------
> id card_id id
> type test_id name
> passed
>
> I would like to have a results page which will show a table of cards
> and their results. e.g.
>
> serial | test 1 | test 2 | test 3 | test 4
> 1 PASS PASS FAIL PASS
> 2 ........
>
> This is fine, but I would like to be able to reference each test by
> name rather than id to fetch the result. It should be relatively easy
> but I can''t seem to work it out.
>
> Am I going about it the right way? I also briefly tried using a
> Results model as a transaction table and 2 has_many relations but that
> seemed even worse in accomplishing what I want.
>
> Thanks in advance,
> Sam Pohlenz
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>