Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
why did i obtain tow results from my query while i expected to get only one result.
  • as i am sure that in my table, i had just one  record of what i wanted, 
    this query that i wrote brought tow result and thus i had to use get_one() function 

    $article = Model_Article::query()
    ->where('slug',$slug)
    ->order_by('created_at' ,'desc')->get();

      


  • HarroHarro
    Accepted Answer
    If you get two, there are two. The ORM does not have a habbit of inventing data.

    And it's really a bad idea to ignore an issue with your code or data, and work around it. The fact that get_one() gives you only one result doesn't mean your problem has no disappeared.
  • Dear harro
    thank you for the fast replay ,because I was inexperienced, I mistook between get_one() and get() function as i thought get() function must give me one object and  foreach syntax is not required .
      
  • get() gets everything so the result is an array with zero, one or more objects.

    Your initial post said that you got more results while you were sure the database contained only one, which is why I responded the way I did.

    If you meant to say it returned an array with 1 object in it, then it's ok.

Howdy, Stranger!

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

In this Discussion