Forum: Ruby on Rails Tips for Data Model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
98328b45bf5bde231d21649bc53153ad?d=identicon&s=25 gil (Guest)
on 2008-12-11 09:27
(Received via mailing list)
I can't quite seem to get the data model down for a fairly simple set
of data.

The data is:

Framework --> Strand --> Level --> Benchmark

It would be simple enough if there were only three levels but since
there are four I can't use  straight has_many xyz :through clause.

The end goal is to have users be able to select a framework, then a
strand, then a level, then a benchmark.

Any help would be appreciated.
Ed437e52d8d6720308720e7e678f3e6d?d=identicon&s=25 Patrick Doyle (Guest)
on 2008-12-11 14:15
(Received via mailing list)
I'm not sure I understand why the number of levels (3, 4, or 104) is an
issue.  So, perhaps I'm not understanding your question.  But why not:

class Framework < ActiveRecord::Base
  has_many :strands, :dependent => :destroy
end

class Strand < ActiveRecord::Base
  belongs_to :framework
  has_many :levels, :dependent => :destroy
end

class Level < ActiveRecord::Base
  belongs_to :strand
  has_many :benchmarks, :dependent => :destroy
end

class Benchmark < ActiveRecord::Base
  belongs_to :level
end

--wpd
This topic is locked and can not be replied to.