G
G
Grigory Vasilkov2021-07-11 21:31:08
Laravel
Grigory Vasilkov, 2021-07-11 21:31:08

How to get eloquent models using JOIN?

I don't really like these
```
SELECT * WHERE EXISTS (SELECT * FROM t2 WHERE t2.sub_id = t1.id) FROM t1
```
No matter how much I studied SQL theory - joins and foreign keys were optimizers, cutters and query simplifiers. When Lara compulsively insists on giving up on joins and using the full selection, it makes me cringe.

Or who has a proof that it is still fast and no difference?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jazzus, 2021-07-11
@jazzus

Lara is a framework. Designed for simplicity, speed, beauty, for all sorts of mvp, startups, mini-teams, etc. Performance sags - optimize. Does not sag - use a framework. The framework for the project is not suitable - do not use it. Everything is simple)

V
vism, 2021-07-11
@vism

How many did not learn the theory of SQL - joins and foreign keys were optimizers, trimmers and query simplifiers.

He taught very badly.
Even EXPLAIN did not learn.

V
Vyacheslav Plisko, 2021-07-13
@AmdY

Badly taught. Firstly, you operate with the word SQL, although in reality you need to work with a specific database and even a specific version of it. The behavior may depend on the base, version, optimizer operation, amount of data, cache availability, etc.
My experience tells me that on large projects where query speed really matters, JOIN is almost always abandoned. Subqueries allow you to build hybrid storage, cache and distribute data well.
Well, everything needs to be checked on your real projects, using explain and other profilers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question