I
I
Ivan Ivanov2017-08-22 22:41:00
PHP
Ivan Ivanov, 2017-08-22 22:41:00

How to create a relationship between tables?

Hello.
Please tell me how to solve this problem: it is necessary to store information about clients, legal entities, and their contact persons in the database.
Created 3 tables: Legal entities, Contact persons and Phone numbers (since one client can have several contact numbers).
But I can’t figure out how to organize links between these tables, because the number can belong to a legal entity (multichannel number) or to a specific employee.
So far, I just came up with the idea of ​​storing the type of the object to which it belongs along with the number and only then making a request to this object. Can it be possible to do this only by means of the database without unnecessary queries?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sl0, 2019-04-26
@ilovv

$books = R::findCollection('books', 'WHERE subject=2 AND class IN (7-9) ORDER BY authors DESC');
This is if the class is given by a single number, and not by the string "7-9".
And if it's still a string, then you just need to add quotes.
$books = R::findCollection('books', 'WHERE subject=2 AND class="7-9" ORDER BY authors DESC');

E
Exploding, 2017-08-22
@Exploding

Well, I'm tab. I represent numbers as follows:
id
object_id - one-to-many relationship
phone - phone number.
name - Person's name
description - Comment. For example: accountant
And the third table can be deleted...
Or the 3rd table can be used as a type reference, if this is an important parameter in the work...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question