We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Model::find vs PHQL performance

My problem is similar to this one https://stackoverflow.com/questions/28755079/phalcon-performance-related-queries When I have a relation between two models and use $results = Projects::find(); this generates many select-statements.

In PHQL I would write one JOIN and get all the data. So I wonder if there is a huge performance difference between these methods?

E.g. I have 10.000 data entries and want to select all of them. Do the user notice the performance difference when I use JOIN instead of Model::find()?

I know I can use the QueryBuilder but this is not as smooth as simply using $results = Projects::find(); Or is there a possibility to use the find method with a join?

edited May '16

Of course. you need to use querybuilder if you want to make JOIN. No there is no possibility to use find method with a join. You can use criteria though - like Projects::query() here you can join, but you can't access your class from which you select with alias.

It's just normal behaviour, in like all orms if you don't select with JOIN then well there will be many select statements to select related records.

Of course he will notice performance difference. It's like you are doing 10001 select statements vs 1 select statement(i know it's too simple, and you have to consider that JOIN is really a select statement when you explain it)

Use eager loading it will prequery and attach the relations simply by typeing Projects::with('authors', 'owner.emails'); etc... Eagerloading only available with https://github.com/phalcon/incubator for now.

Obvius PHQL is most fast, but the models are very useful.