i’m a newbie digging ROR for a week (and loving it i might add) and
trying to get a project done at the same time. i’m more used to
direct SQL so trying to get hang of active record asssociations and
figure out what is done for me and what is not by script/generate
model and db:migrate.
in a nutshell, i have 3 core models where users enter competitions
will need to:
pull all submissions by competition
pull all users by competition
pull all competitions by user
pull all submissions by user
- is this a case of has_many :through like so?
class Competition < ActiveRecord::Base
has_many :users, :through => :submission
class Submission < ActiveRecord::Base
class User < ActiveRecord::Base
has_many :competitions, :through => :submissions
do i create joining tables and define FKs by updating migration
script manually? if there are materials on step instructions you can
point me to, that will be great too!
if i need to add polymorphic behaviors(e.g. commentable and
rateable) to each of these models, do i just pile up the association
definitions? after adding on media and various type/category models,
this probably will get pretty long and not sure whether cache/memory/
performance situation will become unmanageable. An example of
relatively complex association definition will give me a good idea.
thx for reading.