Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fatal error while joing many related table
  • Dear,

    I getting some kind of error in a foreach loop.

    each has many relations.to generate reports, i need to get most of the data from many table, getting


    Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 65488 bytes) in D:\xampp\htdocs\size.dev\fuel\packages\orm\classes\model.php on line 2086



    first time it was 128MB. i changed to 256 in php.ini. still i getting error. How i fix it
    http://bin.fuelphp.com/snippet/view/MF

    my code given above.. Any Batch Processing available in orm?
  • HarroHarro
    Accepted Answer
    Nothing much you can do about it I think. I assume you are pulling in a lot of records, each row may create a lot of objects.

    For example, if you have a parent with 10 children, each having 10 childeren as well, you're creating 111 ( 1 + 10 + 10x10 ) objects.

    It is probably a lot more memory efficient you code DB calls for reports, or use get_query() instead of get() to get the SQL generated by the ORM, and then use a DB::query() to execute it.

    Yes, Fuel has batch processing available through Oil tasks, but they are restrictedd to the same memory limit.
  • Exactly, What is the difference between using get() and DB::query().

    Any memory advantages?
    Is response is same?

    i fixed it by another method.. http://bin.fuelphp.com/snippet/view/MG
    now i got no memory truble. but having 24 query.. all are becasue of eav i think so.

    Also.....

    i have some kind of EAV available. But when ever i call $model->eav_custom_field   , i think a new query is executed. I cause memory trubles as so many eav queries are there,
    can i attach/join the eav meta table parent table? so that further query to every eav request can be avoided.

    also.

    can you provide me a solution that i can free up memory of orm object after its use on the fly  in a foreach loop. i have much truble at reports.
  • HarroHarro
    Accepted Answer
    DB::query() returns raw row responses, either in an array or in an object.

    ORM get() does the same, but then hydrates the result by spliting the row into the different objects the row contains, creating relations between the objects, etc.

    In case of EAV, it's a standard related table. It means that you either include it (by using the related() method) in your query to load it all up from, or the rows get lazy-loaded when you access the property, which indeed will fire a query per EAV attribute.

    And you can't, that is the downside of using the ORM. It holds an object cache, and because of all relations you can't simply delete objects without creating side effects.

    Hence the statement that you should not use ORM for reports and batch operations, it has way to much overhead.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion