I'm sorry, thats amazing :)
what if I don't know how many tags ids I need?
will DM let me do something like this:
ids = [1,2,3]
@results = Article.all("tags.id" = 1)
ids.each do |i|
& Article.all("tags.id" = i)
end
Thanks a million for that :)
On Jul 7, 3:30 pm, Yuri Smirnov <[email protected]> wrote:
> Article.all("tags.id" => 2) & Article.all("tags.id" => 3) should work. It
> actually produces 3 queries but I don't think this will work longer then
> your one.
>
> 2010/7/7 deco <[email protected]>
>
>
>
> > How would I get datamapper to produce a query like this?
>
> > In this example I'm attempting to return the articles that have the
> > tags with id 2 and 3.
>
> > SELECT * FROM `articles`
> > JOIN `article_tags` ON article_id = `articles`.`id`
> > WHERE `tag_id` = 2
> > AND EXISTS(SELECT * FROM article_tags WHERE tag_id = 3 AND article_id
> > = `articles`.`id`)
>
> > - ** Row 4 could appear several times depending on the number of tags
> > being searched.
>
> > TABLE: tags
> > id, tagtext
>
> > TABLE: articles
> > id, body, title
>
> > TABLE: article_tags
> > id, tag_id, article_id
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "DataMapper" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<datamapper%2bunsubscr...@googlegrou
> > ps.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/datamapper?hl=en.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.