How to organize communication between components in the database?

Hello. Currently rewriting one app since last DB scheme was terrible.

There are two modules:
  • Blog
  • Company


Blogs can have both companies and users. Also each company to relate to a specific user.

Frequent operations:
  • A sampling of blogs and user companies which he owns.
  • Check who owns the blog article, if it is the company who owns it.


Requirements:
  • Scalability
  • Ease of use


Technology:
  • MariDB
  • laravel

5e976f64207c6967240947.png
At the moment, got rid of the binding tables, adding a polymorphic relationship in the table Blog. But it seems that the scheme is not correct, help to achieve the "ideal" structure
April 19th 20 at 12:14
2 answers
April 19th 20 at 12:16
Solution
in the blogs table I do have two fields: user_id and company_id
so logical and less confusion
And if there was another entity that also can have a blog? - cullen_Roberts commented on April 19th 20 at 12:19
Then I add another column - obviously =)
sarcasm. - bailee.Heidenreich commented on April 19th 20 at 12:22
@cullen_Roberts, then you can even add a separate table where it will be done in your principle, but not in the blogs table. and if not will add the essence, why complicate things? - gabrielle.Kshlerin commented on April 19th 20 at 12:25
@gabrielle.Kshlerinin the near future plans to add a new entity. - cullen_Roberts commented on April 19th 20 at 12:28
@cullen_Roberts, then you can do a separate table entities according to the principle - gabrielle.Kshlerin commented on April 19th 20 at 12:31
April 19th 20 at 12:18
Now everything is OK.
"But it seems that the scheme is not true" - what exactly does not suit you?
Just a thought, for example we need to know by article id the user's email. Not too complex query for a frequent and simple operation ? - cullen_Roberts commented on April 19th 20 at 12:21
There will be 2 request - getting a blog and if the owner of the user - receiving names.
Put indexes on the most common conditions and everything will be OK. - bailee.Heidenreich commented on April 19th 20 at 12:24

Find more questions by tags Database designMySQL