views:

434

answers:

1

Hello. 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?

A: 

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.

David Caunt
$this->model is a User.
Typeoneerror
Sorry, it's confusing, I used "model" as my object key [partialLoop()->setObjectKey("model")] in partialLoop
Typeoneerror
Plus, as I said in the OP, it works as expended *without* passing a select object. I can get a rowset of the user's articles, but not a "filtered" rowset.
Typeoneerror

related questions