TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Help with model relationship design for a buyers and sellers schema
  • I am building an exchange website where you can buy and sell cryptocurrency like Bitcoin and am currently stuck on one aspect (its been a long day, so maybe I am just tired). Essentially what I have is a users table and in the users table a user can be either a; seller, buyer or hybrid (meaning both a seller and buyer).

    What would the relationships look like in this instance if a user can be theoretically 3 different types of user? Then when you get to the orders table, it has both a seller_id and a buyer_id so buyers and sellers can wuerying for items they are selling and buyers can query for items they are buying. It's boggling my mind.

    Thanks for your help!

  • If you have only 1 seller and 1 buyer for every transaction, than this would be a one-to-many relationship like this:

    transactions.seller = users.id (indexed and with FK constraint)
    transactions.buyer = users.id (indexed and with FK constraint)

    If you can have multiple buyers or multiple sellers for every transaction, then you will need an intermediary table:

    intermediary.user = users.id
    intermediary.persona = ('buyer','seller','hybrid')
    intermediary.transaction = transactions.id

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion