Please help, I'm sure I'm over looking something silly, but I cannot
query by category. Everything works great except the last line returns
" Unknown property 'category'" error. Same if I use the (:conditions
=> ...... ) syntax.
Thanks,
Dan
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/test.sqlite3")
DataMapper::Logger.new(STDOUT, :debug)
# :off, :fatal, :error, :warn, :info, :debug
DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, 0)
class Url
include DataMapper::Resource
property :id, Integer, :serial => true
property :url, Text, :nullable => false
has n, :categorizations
has n, :categories,
:through => :categorizations,
:class_name => 'Category',
:mutable => true
end
class Category
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :categorizations
has n, :urls, :through => :categorizations, :mutable => true
end
class Categorization
include DataMapper::Resource
property :id, Serial
belongs_to :category
belongs_to :url
end
DataMapper.auto_migrate!
cat1 = Category.new
cat1.name = "Cat1"
cat1.save
cat2 = Category.new
cat2.name = "Cat2"
cat2.save
Category.all
url1 = Url.new
url1.url = "http://yahoo.com"
url1.save
url2 = Url.new
url2.url = "http://google.com"
url2.save
catID = Category.first.id
urlID = Url.first.id
Categorization.create(:category_id => catID, :url_id => urlID)
urls = Url.all(:category => catID)
ArgumentError: Unknown property 'category'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/query.rb:
462:in `append_condition'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/query.rb:
246:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/query.rb:
245:in `each'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/query.rb:
245:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/model.rb:
431:in `new'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/model.rb:
431:in `scoped_query'
from /usr/lib/ruby/gems/1.8/gems/dm-core-0.9.11/lib/dm-core/model.rb:
256:in `all'
from (irb):66
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---