A
A
Andrey Eskov2016-03-30 10:26:11
MySQL
Andrey Eskov, 2016-03-30 10:26:11

How to use relationships when there are many entities?

Dear, tell me how to implement it correctly.
There are 2 entities: Deals, Tasks. They need to attach halyards.
It was decided to use 1 table with a link to the entity.
The table has the following fields:
id,
component('deal' or 'task', i.e. an entity pointer),
item_id (ID of the record itself, whether it's a deal or a task)
And then the file information fields.
Now tell me how to use relationships in such a table?
I understand that you can choose the required File::find and so on, but I would like, for example, to delete the transaction and the files to be deleted.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2016-03-30
@taurus2790

select something from table1 as t
INNER JOIN сделки as s ON s.id = t.itemId AND t.component = 'сделки'
INNER JOIN сущности as s1 ON s1.id = t.itemId AND t.component = 'сущности'

It is possible for example like this. But in my opinion the idea is so-so. I would probably make a "Files"(id,filedata) table and a set of tables like DealFiles(DealId,FileId) , TaskFiles(TaskId, FileId)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question