Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Wierd results from find method
  • I'm not sure if i fuxed up somewhere, or if it's a bug in the ORM. I'm looping over all files in a dir, and for each file with a defined extension, check if it's already in the database with the following query.
    $movie = Model_Movie::find('first',array(
            'related' => array(
                    'file' => array(
                            'where' => array(
                                    array(
                                            'path', '=', $fullpath . $movie_file
                                      )
                               )
                      )
              )
        ));
    
    My problem is, that the first file it checks, a record is found and it's all good.
    But when it checks the rest of the files, no record is found. All records were inserted by the ORM and I've manually verified that they exist in the database.
    I've tried manually executing the same query as the ORM (taken from the profiler) and this doesnt return any results, even though the only difference between the successful and failing query is the path - of which both exist in the DB. If I'm using 'all' instead of 'first' as the first param to find(), an array is returned with the correct result each time, but the index of the model is increased for each file checked. Any idea what's causing this? Models: http://pastebin.com/ay5VYDb7
  • Have you activated the profiler to see what queries are generated by your loop?
  • Yup. See http://pastebin.com/NKWHg7f8 for queries. The forum cuts the query off :p The only thing that differs is the path, but the query result is different
  • Ah, find('first') runs a get_one() query. If you combine get_one()'s with relations, the design of the ORM will ensure you get consistent data. It refuses to run a JOIN on a has_many relation with a limit, as that would probably mean the results are incomplete (not all records are joined due to the limit). Which means the query will be converted into a subquery instead of a simple JOIN, with a limit on the subquery. And this may produce different results from what you expect. So, no bug, by design.

Howdy, Stranger!

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

In this Discussion