In the codebase, there are objects called Bundles. There are also
Sites. The sites have a bundle_id field which may be null. (The
bundles contain information about where to locate serialized data
relevant to the operation of the collection of services which the site
objects represent.)
In my code, I have a list of sites, and wish to determine the set of
bundles which those sites use. I figured an easy way to do it would be
to call
bundles = MyOrg::Model::Bundle.all(:sites => sites)
In the common case, this works. It also works if sites = []. However,
if none of the sites have a bundle, the query returns every single
bundle in the database. Besides representing a potential performance
problem, this would also result in massive data leakage.
I assume that I'm either Doing It wRong, or that DataMapper is busted.
I'm using DataMapper 1.1.0 on Ruby 1.9.2p180 with Postgres 9.0.0.
Here is the problem in code snippets.
def test_my_sanity
make_test_db! # db:test:migrate, if necessary, then delete
everything from all the tables
bundle = MyOrg::Model::Bundle.create(:name => "cordately-
resinbush")
bundle2 = MyOrg::Model::Bundle.create(:name => "splanchnomegaly-
flickerproof")
unbundled_site = MyOrg::Model::Site.create(:name => 'mammillated-
grinderman')
bundled_site = MyOrg::Model::Site.create(
:name => 'peripericarditis-prepronouncement',
:bundle => bundle,
)
assert_equal( nil, unbundled_site.bundle_id )
assert_equal( nil, unbundled_site.bundle )
assert_equal( [], MyOrg::Model::Bundle.all(:sites => []) )
assert_equal( [bundle], MyOrg::Model::Bundle.all(:sites =>
[bundled_site]) )
assert_equal( [bundle], MyOrg::Model::Bundle.all(:sites =>
[bundled_site, unbundled_site]) )
# so far so good...
assert_equal( [], MyOrg::Model::Bundle.all(:sites =>
[unbundled_site]) )
# this one actually returns [bundle, bundle2]. wtf?
end
require 'dm-core'
require 'dm-types'
class MyOrg::Model::Bundle < MyOrg::Model::Base
# the base class is rather boring
property :id, Serial
property :name, Text, :required => true
has n, :sites
end
class MyOrg::Model::Site < MyOrg::Model::Base
property :id, Serial
property :name, Text, :lazy => false
belongs_to :bundle, :required => false
# in the database, site has a bundle_id field.
end
--
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.