Relationship modelling problem

I have battled with this for ages and would love some guidance

I am building an app that has:
Companies
Products

A product belongs to a company and a company has many products and
hence: this company is a supplier

A company has many products and hence is a client

Every-time I give all relationships in the models it breaks and I think
its due to the fact that the logic is broken as the separation of
weather I am calling for clients or suppliers is not there and the model
as I see it is broken because of the ambiguity

My models look as follows:

Company
has many products
has many assignments
has many products through assignments

Products
belongs to company
has many assignments
has many companies through assignments

Assignments
belongs to company
belongs to product

What is the best way to implement this and what controller do I use to
call what relationship and how do I separate the difference of calling
clients or suppliers (both being companies)

I have been at this for ages and am at my bitter end in terms of trying
to work it out myself

I think I am going to try this:

Create the model Company: name:string
Create Client: company_id:integer
Create Supplier: company_id:integer
Create Product: name:string
Create Clientship: company_id:integer, product_id:integer
Create Suppliership: company_id:integer, product_id:integer

Company
has many :clients
has many suppliers
has many supplierships
has many products through supplierships

Client
belongs to :company
has many :clientships
has many :products, through clientship

Supplier
belongs to :company
has many :supplierships
has many :products through supplierships

Product
has many supplierships
has many companies through supplierships
has many clientship
has many companies through clientships

Suppliership
belongs to company
belongs to product

Clientship
belongs to company
belongs to product

Generate a Controller for Clients, Products and Supplier
Then I can use:
Company.supierships to get suppliers (company names)
Company.clientships to get the clients (company names)

So I still have one place storing companies and they are then not split

I will let everyone know where I get to : if you have any pointers or if
there is a better way of doing it let me know
Polymorphic can be used as its used I think to draw relations to a model
however in this case the model is based on a relationship: If it has a
product issues as client or supplier.

On Sat, Jan 22, 2011 at 4:25 AM, Craig L. [email protected]
wrote:

has many products through assignments
What is the best way to implement this and what controller do I use to
call what relationship and how do I separate the difference of calling
clients or suppliers (both being companies)

I have been at this for ages and am at my bitter end in terms of trying
to work it out myself

I would highly recommend you try to work this out in a test-driven
manner.
That lets you start from simple to more complex and getting each piece
working before you go further. That way, when you do hit the part where
you
start having problems, you have a laser focus on the problem and if it
gets
fixed (and if the fix breaks something else!)… I find that whatever
the
issue is, going about it this way makes it much easier to solve the
problem.

That said, if you do not go this route, you should probably post your
pertinent code and error messages concretely. Otherwise the person
reading
your message has to go and do the same background work in their head to
reconstruct what you have already done.

Thanks for the reply David
My app was working until I added the client model and relationships

I think you have given me good direction in terms of trying from the
base up and testing using the console is something I need to master as
it will then give me a good understanding of modeling and methods I can
call based on the relationships

Thanks again

On Sat, Jan 22, 2011 at 10:29 AM, Craig L. [email protected]
wrote:

has many :clients
belongs to :company
belongs to company
belongs to product

Clientship
belongs to company
belongs to product

PS… these (Suppliership and Clientship) I think are going in a strange
direction. Object oriented should refer to actual things and these are
like
modifiers or adverbs? or something…

More than one model can have one or many objects, i.e.:

A Client can have many products
A Supplier can have many products
A Company can have many products

So you dont need ‘Suppliership’… you can ask for:

Company.Supplier.Products for example (this is pseudocode, but you get
the
picture).

I think you are over-analyzing.