datamapper/dm-core — Issue #161: Query#filter_records does not understand many-to-many relationships
Author: d11wtq
Created: 2011-10-29 11:55:35+00:00
State: open

This affects the `InMemoryAdapter` and any other non-SQL adapters that rely on `Query#filter_records`.

``` ruby
require "dm-core"

DataMapper.setup(:default, :adapter => :in_memory)

class Post
include DataMapper::Resource

property :id, Serial
property :title, String

has n, :tags, :through => Resource
end

class Tag
include DataMapper::Resource

property :id, Serial
property :slug, String

has n, :posts, :through => Resource
end

DataMapper.finalize

post = Post.new(:title => "a post")
tag = post.tags.new(:slug => "a-tag")

[post, tag].each { |r| r.save }

p post.tags # => [#]
p post.post_tags.tags # => [#]
p tag.posts # => []
p tag.post_tags.posts # => [#]

puts "Reloading post (clearing instance variables)"
post.reload

p post.tags # => []
p post.post_tags.tags # => [#]
p tag.posts # => []
p tag.post_tags.posts # => [#]
```

The adapter is just doing:

``` ruby
query.filter_records(records_for(query.model).dup)
```