I am attempting to creat a custom eager loader that uses the model relationships to determine which of the hasOnes and belongsTo relationships that it needs to eagerly fetch from the database so that my query which returns 100 records each having four related models doesn't generate an additional 400 queries to fetch the related models.
It worked while I was building it, up to the point that I started to eager load the belongsTo relationships. When I define the relationships in the model's initialize function, I specify an 'eager' parameter in the options array of the relationship. if this eager parameter is set, my EagerBuilder, which extends Phalcon's Builder, adds the necessary joins.
Now, for whatever reason, I get an Unknown model or alias exception when referencing the fully qualified model name which I'm trying to add a join on. The builder generates the PHQL:
SELECT AMAPI\Models\Note.*, AMAPI\Models\Customer.*, AMAPI\Models\Policy.*, AMAPI\Models\Notetype.*, AMAPI\Models\Employee.*, AMAPI\Models\Employee.* FROM [AMAPI\Models\Note] LEFT JOIN [AMAPI\Models\Customer] AS [customer] ON AMAPI\Models\Note.custid = AMAPI\Models\Customer.id LEFT JOIN [AMAPI\Models\Policy] ON AMAPI\Models\Note.polid = AMAPI\Models\Policy.id LEFT JOIN [AMAPI\Models\Notetype] ON AMAPI\Models\Note.notetype = AMAPI\Models\Notetype.id JOIN [AMAPI\Models\Employee] AS [touser] ON AMAPI\Models\Note.targetuser = AMAPI\Models\Employee.id JOIN [AMAPI\Models\Employee] AS [fromuser] ON AMAPI\Models\Note.user = AMAPI\Models\Employee.id WHERE (AMAPI\Models\Note.masterid = :masterid:) AND (AMAPI\Models\Note.open = :open:)
But it tells me that AMAPI\Models\Customer is unknown when it tries to execute the query. Any insight on this is greatly appreciated. I'd like to eventully get this eager loading library completed and put it on my github, because not eager loading relationships is one of the weakest parts of an otherwise phenomenal framework.
Thanks