Forum: Ruby on Rails relationship help (not a personal problem)

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.
Chris B. (Guest)
on 2005-12-16 21:08
Howdy all.  New to OO and Rails and trying to get a grip on both.

In particular at the moment I'm having trouble figuring out the
following relationship.

Say I have table/class Foo.

Users get to decide to create Foo (or update or delete Foo) based on a
user first proposing a change (class FooProposal), then users voting on
that change (class FooProposalBallot).

I was thinking something like ...

class Foo < ActiveRecord::Base
  has_many :foo_proposals # Foo can be changed any # of times
  belongs_to :user # who proposed to create Foo in the first place
end

class FooProposal < ActiveRecord::Base
  has_many :foo_proposal_ballots # each user can vote on a proposal once
  belongs_to :user # who proposed the proposal

  belongs_to :foo
  # ^^^ this is where the majority of my confusion sets in
  # if the proposal is "modify" or "delete", this relationship
  # is straight-forward; however if the proposal is "create" I'm not
sure
  # if I should create Foo and set some flag that indicates Foo hasn't
  # been approved yet

end

class FooProposalBallot < ActiveRecord::Base
  belongs_to :foo_proposal
  belongs_to :user
end

Any thoughts?

Thanks
This topic is locked and can not be replied to.