Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Conflicting queries


  • Hello again
    FuelPHP forum.



    I am hoping
    I can get help resolving this strange problem.



    From the
    home page of a “RN | Wall Street Journal” website you can click on an article
    to read.



    Controller_Frontend_Index->action_article($slug)
    takes care of setting the section category in the header, as well
    as fetching post content.

    The problem is that if both queries are run than I
    get missing data. But if I run either of the set of queries on their own I get
    the correct data. Why are these queries conflicting with each other?

    References:

    https://github.com/daniel-rodas/wsj/blob/master/fuel/app/classes/controller/frontend/index.php

    Demo

    http://wsj.rodasnet.com/maternity-and-paternity-in-the-workforce



  • Can you be more specific? I can see three queries in that code, what do you mean by "both"?
  • HarroHarro
    Accepted Answer
    Ah, wait, I think I see what you mean.

    Your first query uses select(). Although you can do that, you should NOT use it in normal circumstances, the ORM is not a query builder.

    ORM objects are cached for performance, your first query creates the post object with only one field, the second query (which is redundant as it is a query for the same object btw) returns the cached object instead of running a new query, an object that is incomplete due to the select.
  • Very well I will refactor accordingly. The reason for the redundancy is that I had all that controller code in separate methods in a blog module but now I will use packages instead and eventually I would like to be able to install the blog package via composer. Thank you for the fast response.

Howdy, Stranger!

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

In this Discussion