Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
'related' only returns 1 item in _many_many relationship. v1.1RC1
  • I'm specifying my find query like this:
    $categs = Model_Categ::find('all', array (
                            'related' => array ('articles'),
       'offset' => Pagination::$offset,
       'limit' => Pagination::$per_page,
       'where' => array(
        array('user_id', '=', $this->user_id),
       ),
      ));
    

    and including on the most basic $_many_many statement in my model:
    protected static $_many_many = array('articles');
    

    I've tried using Debug::dump ($arrayname) to view the raw contents of the related items array ($articles) and it definitely contains only one related article per category. I've used the profiler to dump the SQL within the orm query above.
    Running it directly against the database returns the correct resultset; it shows more than one article being returned for each category. They seem to get "lost" somehow between the database query and the View. I've seen references to only one row being returned in 1.1; is this the case? I've tried changing the join type with
    'related' => array('articles',  array('join_type' => 'inner'))   
    
    to see if anything revealing happened; the app crashed with:
    UnexpectedValueException [ Error ]: Relation "1" was not found in the model.
    
    461        else
    462        {
    463            $rel = call_user_func(array($this->model, 'relations'), $relation);
    464            if (empty($rel))
    465            {
    466                throw new \UnexpectedValueException('Relation "'.$relation.'" was not found in the model.');
    467            }
    468        }
    469
    470        $this->relations[$relation] = array($rel, $conditions);
    471
    
    Backtrace
    
    PKGPATH/orm/classes/query.php @ line 442
    PKGPATH/orm/classes/query.php @ line 114
    PKGPATH/orm/classes/query.php @ line 31
    PKGPATH/orm/classes/model.php @ line 436
    PKGPATH/orm/classes/model.php @ line 390
    APPPATH/classes/controller/categs.php @ line 28
    COREPATH/classes/request.php @ line 443
    DOCROOT/index.php @ line 38
    
    

    I'm a noob at this; would very much appreciate some help.
  • Known bug, has been fixed in develop. Also your code was wrong:
    // This:
    'related' => array('articles',  array('join_type' => 'inner'))
    
    // Should be:
    'related' => array('articles' =>  array('join_type' => 'inner'))
    
  • Thanks; I've now made a clean install from the 1.1 develop branch.
    Unfortunately I'm now running into a redirect loop before I can even get to the app.
    I've tried simply adding the "created_at" column to my users table; but still get "too many redirects". Is there any simple you can think of, or just a general refactoring necessary from 1.1 to 1.1 dev.
  • The difference should be bugfixes, but I can't see your code so I have no clue why it'd keep redirecting. You'll have to track that down yourself.

Howdy, Stranger!

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

In this Discussion