Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Mongo get() behavior
  • Let's say that I have a bunch of widget data in mongo. * Collection A contains inventory data about each widget * Collection B contains pricing data about each widget. Now let's say I wanted to connect inventory and pricing data and show the lowest price of all red widgets.
    $red_widgets = $db->get_where('inventory', array('color' => red)); 
    
    $prices = array();
    
    foreach($red_widgets as $widget)
    {
       array_push($prices, $db->get_where('prices', array('id' => $widget['id])));
    }
    
    echo min($prices);
    

    Ignore the fact that this is, perhaps, a crappy example. The point is that the above code doesn't work as expected. It appears as though the $wheres variable never gets cleared between the two get_where() function calls. So to work around this I do something like this in the model:
    $db->wheres = array(); // reset the $wheres 
    

    But I have to ask if this is the intended method of use? Adding the following to the end of the get() function in the core seems like a more sensible behavior:
       ...
       $this->_clear();
       return (object) $returns;
    }
    

    Has anyone else run into this? Am I doing it right? Am I missing something? Should I go ahead and add this into the core and submit a pull request? Thanks! EDIT: Formatting and typo
  • Relevant: https://github.com/fuel/core/issues/387 I guess it's already slated to be fixed. Cool.

Howdy, Stranger!

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

In this Discussion