Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Is it possible to query slim model classes?

Hello,

I was digging around in the docs for some time but could not find an answer to this: Is it possible to tell a "Robots" class ( which extends \Phalcon\Mvc\Model ) to return simple "Robot" objects that do not extend \Phalcon\Mvc\Model ?

I'm asking because I'm working on a spatial application that will handle 10000s of objects at runtime. And it will make a significant impact on memory usage when I could query slim "Robot" objects instead of fat "Robots" objects.

Regards



8.6k

Hi dempie,

I would say this is not a question to the phalcon framework than to php in general. If you only neet the database interaction from the \Phalcon\Mvc\Model than you could try to create an extra class "RobotsOne" with no parent with the method getRobot. In the getRobot you fetch all the data you need from the Robots class which is a child of \Phalcon\Mvc\Model.

greetings Eike



5.5k

Thanks, this sounds quite reasonable to overwrite the \Phalcon\Mvc\Model methods to return simple "Robot" classes (if that's what you pointing at). I'll give it a try.



8.6k

No I don't mean to overwrite the \Phalcon\Mvc\Model. You create a very new class which has no parent and has the method getRobot. In this method you create a new instance of Robots and return it. This Robots is a child of \Phalcon\Mvc\Model. Hope this was clearer ;)



5.5k

Ah, yes. This would be also another solution. But I'd prefer to overload / add find function(s) that return slim objects.



461
Accepted
answer

I'm sorry if I am missing something, but isn't this what the hydration mode refers to? See at: http://docs.phalconphp.com/en/latest/reference/models.html#hydration-modes. So in your case the smallest result you can return is HYDRATE::ARRAYS



5.5k

Ah, yes. This also decreases memory usage when retrieving objects from DB - thanks for the pointer.