topclaudy / compoships

Multi-columns relationships for Laravel's Eloquent ORM
MIT License
1.12k stars 130 forks source link

Using `OR` instead of `AND` in the association #129

Open undjike opened 2 years ago

undjike commented 2 years ago

Please, is it possible to use OR in the association?

foreing_key_1 = local_key_1 OR foreing_key_2 = local_key_2
undjike commented 2 years ago

Pls, need help 🙏

undjike commented 2 years ago

@topclaudy, what about this?

topclaudy commented 2 years ago

@undjike Some people have requested different association logics. Can you please explain the use case(s) for this?

undjike commented 2 years ago

OK, let me explain. I have a transaction table with some fields

When we have a transfer, both deposit and withdrawal are performed in the accounts concerned by the operation. So, this is the structure of the transfer table...

Then, when I'm to retrieve (with eager loading) the transfer associated to a transaction, I have to join using transaction.id = transfer.withdraw_id or transaction.id = transfer.deposit_id.

That's the point.

topclaudy commented 2 years ago

@undjike Thanks for the explanation. Please check discussion on https://github.com/topclaudy/compoships/issues/76 and https://github.com/topclaudy/compoships/issues/67. Such features are not on the roadmap.

neacon-ivalkenburg commented 1 year ago

Would really like to be able to use OR. But i can see why it could be a pain to add due to associating models.