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

When models related data called : at new instance / call alias

Hello Team

i have a question about relationship in models

for example i set up model Test like : Test::class -> hasMany( a , Realted::class , b , [ alias => related ] )

does related data fetched at beginning of model call or after calling test.related ?



125.7k
Accepted
answer

It's lazy, so the query to retrieve the related models doesn't happen until you call $TestObject->related.

Ok ! That's useful to know

thanks !