miso

One-to-zero-or-one relationship

Posted 3 years ago by miso

Hi, is is possible to create one-to-zero-or-one ORM relationship?

Example: offer[offer_id, product_id] product[product_id]

Details:

  • offer MUST have exactly 1 product
  • product MUST have 0 offers or 1 offer (in other words, product will or will not be assigned to offer)
  • if product have 0 offers, in the future will have 0 offers (when connecting offer with product, the product is cloned)

Implementation

I am not sure if to make NULLABLE FK product_id or make third table offer_product[offer_id,product_id] with UNIQUE constrains.

Thank you

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.