0

Currently learning Rails, so be gentle.

I want to check that i'm getting this right before I go to far:

Building an app that allows our 'Customers' to log in, and create a quote. 'Suppliers' (in this case conference venue owners) can then look a the quotes, and reply to them with a proposal, which the customer will be able to view. Each Supplier account will have the option to have one or more 'Venues' that belong to it (if they run a chain of venues for instance), and each proposal made will be from a specific venue.

Other complicated issues that I will probably come across later on, does this look right as far as the relationships go?

P.S I realise that the below is not actually code that will work, I just laid it out like this whilst I attempt to get my head around it.

Customer (will be a type of user)
has_many :quotes
has_many :proposals, :through => :venue

Supplier (will be a type of user)
has_many :venues
has_many :proposals, :through => :venue

Venue
belongs_to :supplier 
has_many Proposals

Quote
belongs_to :customer

Proposal
belongs_to :venue

And the basic tables:

Customer
    id

Supplier
    id

Quote
    id
    customer_id

Venue
    id
    supplier_id

Proposal
    id
    venue_id

There might be a much better way to do this, using has_ones and has_and_belongs_to_many etc, but i've no idea.

Thanks

4
  • How do you want customers to be related with venues? 'Cause if you want customers to have many proposals through venues, customers should also have many venues. Jun 23, 2013 at 10:25
  • Customers could pick up proposals from any venue - perhaps I don't need the through's? Could I remove both of those?
    – Ralph King
    Jun 23, 2013 at 11:05
  • So you should remove :through at least from Customer has_many :proposals. How do you want your suppliers connected with proposals? Jun 23, 2013 at 11:07
  • Each supplier would have many proposals - but each proposal would be from a specific venue, and each venue would belong to a certain supplier. (I could have done away with the 'venue' model, but it stops suppliers having to sign up to the site for each venue they own - I think...
    – Ralph King
    Jun 23, 2013 at 11:12

1 Answer 1

0

Ok, so I think it should look like this:

Customer
  has_many :quotes
  has_many :proposals

Supplier
  has_many :venues
  has_many :proposals, :through => :venues

Venue
  belongs_to :supplier 
  has_many :proposals

Quote
  belongs_to :customer

Proposal
  belongs_to :venue
  belongs_to :customer

and in db schema:

Customer
  id

Supplier
  id

Quote
  id
  customer_id

Venue
  id
  supplier_id

Proposal
  id
  venue_id
  customer_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.