Rails3: how to use relational algebra to replace SQL-constructions like NOT and OUTER JOIN

Posted by petRUShka on Stack Overflow See other posts from Stack Overflow or by petRUShka
Published on 2010-06-06T20:18:04Z Indexed on 2010/06/06 20:22 UTC
Read the original article Hit count: 323

There are two models Post and Comment. I should get all posts, which have no comments with specific tag. How can I do this using new Rails 3 features such relational algebra (arel).

SQL-solution should be something like this:

SELECT     `posts`.* FROM       `posts` LEFT OUTER JOIN `comments` ON `posts`.`id` = `comments`.`post_id`
WHERE    NOT (`comments`.`tag` = 'my_tag')

© Stack Overflow or respective owner

Related posts about ruby-on-rails3

Related posts about outer-join