2
2
2Ernest52021-03-17 17:54:33
SQLite
2Ernest5, 2021-03-17 17:54:33

How to use OR in sequelize?

I am writing a CRM system. There are 2 tables: in one users (parents), in another children. The child has 2 columns for parents (mom, dad).

The question is, how do I get the right child if the parent can be in one of the child's two fields? I used findOne() before, is it possible to use or here?60521827eb26c805183419.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
acwartz, 2021-03-18
@acwartz

create a Relationships table instead of parent1, parent2:
Autokey, PersonAID, PersonBID, RelationType
then you can add any type of relationship PersonAID to PersonBID, not only for User to Children but also User to User and even Children to Children
Where in your case there will be 2 records with different User.ID and the same Children.ID

M
Maxim, 2021-03-18
@MaximaXXl

Doesn't SQLite have an in operator?
check how in works if one of Parent is null. (recommendation if you don't know)
user.id in (Children.Parent1, Clildren.Parent2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question