views:

66

answers:

0

I am trying to return an intersection of datamapper collections relating to tagged topics.

Before we go any further I should point out the obvious:

@tags = Tag.all(:title => ["shim", "sham"])
@tags.topics

This returns a UNION which means I get all topics with either 'shim' or 'sham' as a tag.

What I want to do is return all articles that have BOTH 'shim' AND 'sham' as tags.

@tags = Tag.all(:title => ["shim","sham"])
@blah = []
@blah << @tags.topics.first
@tags.each do |tag| @blah = @blah & tag.topics end

Ok, we have our data -- now we still have one problem. We need to have this as a DataMapper collection so I can drilldown my results effectively like so:

@topics = @blah(:order => [:created_at.desc], :limit => limit, :offset => offset)

This of course is not possible since @blah is now an array and not a DataMapper Collection.

a more succint version of the above:

@topics = Tag.all(:title => ["shim"]).topics & Tag.all(:title => ["sham"]).topics

although we still end up with an array..... according to http://www.mail-archive.com/[email protected]/msg02092.html this should be possible