Question

I'm trying to use a select object to filter the results of a many to many rowset. This call works great:

$articles = $this->model->findArticlesViaArticlesUsers();

This however does not:

$articles = new Default_Model_Articles();
$articleSelect = $articles->select();
$articleSelect->where("status = 'published'")
              ->order("date_published DESC")
              ->limit(1);

$articles = $this->model->findArticlesViaArticlesUsers($articleSelect);

That throws the following error:

exception 'Zend_Db_Select_Exception' with message 'You cannot define a correlation name 'i' more than once'

I can't figure out how to successfully get "articles that have the status of 'published'" using the magic many-to-many relationship (nor findManyToManyRowset). I'm at the end of my rope and thinking of just writing the sql manually. Any ideas?

Was it helpful?

Solution

When defining the select statement, you must use the same object that you call findManyToManyRowset (or whatever magic function you use) on.

Ex:

$articles = new Default_Model_Articles();
$user = $articles->find($userId)->current();
$select = $user->select();
$select->where('status = ?', 'published');
$articles = $user->findArticlesViaArticlesUsers($select);

Notice the select statement and findArticlesViaArticlesUsers are both extending $user. Thats the key.

OTHER TIPS

I think you've misunderstood how the relationships work.

See this manual page - you should call the magic method, findArticlesViaArticlesUsers, on a Row object. In this case, I think you want to find a User, and then call findArticles... on that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top