Try "categories.id" => [catId] -- Yehuda
On Tue, Apr 21, 2009 at 1:05 AM, Dan D <[email protected]> wrote: > > Tips appreciated, I tried those and a couple other variations, but > still not working: > > irb(main):065:0> urls = Url.all('category.id' => catID) > NoMethodError: undefined method `category' for Url:Class > > > irb(main):066:0> urls = Url.all(:category.id => catID) > (irb):66: warning: Object#id will be deprecated; use Object#object_id > ArgumentError: Condition type 785788 not supported > > > irb(main):067:0> urls = Url.all(:category.category_id => catID) > NoMethodError: undefined method `category_id' for :category:Symbol > from (irb):67 > > > irb(main):069:0> urls = Url.all('categorization.category_id' => > catID) > NoMethodError: undefined method `categorization' for Url:Class > > > > On Apr 21, 12:47 am, Chris Van Pelt <[email protected]> wrote: > > That should be 'categories.id' > > > > On Tue, Apr 21, 2009 at 12:46 AM, Chris Van Pelt <[email protected]> > wrote: > > > > > I'm sorry, I just glanced at the question. I'm not super familiar > > > with DM's facility for has_many_through relationships. I would try > > > > > Url.all('categories'.id => catID) or > > > Url.all('categorization.category_id' => catID) > > > > > I could be way off here though :) > > > > > Chris > > > > > On Tue, Apr 21, 2009 at 12:27 AM, Dan D <[email protected]> wrote: > > > > >> Thanks, but didn't work. > > > > >> irb(main):064:0> urls = Url.all(:category_id => catID) > > >> ArgumentError: Unknown property 'category_id' > > >> 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):64 > > > > >> irb(main):065:0> urls = Url.all(:category_id => 1) > > >> ArgumentError: Unknown property 'category_id' > > > > >> On Apr 20, 11:01 pm, Chris Van Pelt <[email protected]> wrote: > > >>> urls = Url.all(:category => catID) > > > > >>> Should be: > > > > >>> urls = Url.all(:category_id => catID) > > > > >>> On Mon, Apr 20, 2009 at 10:44 PM, Dan D <[email protected]> > wrote: > > > > >>> > 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 > > > -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
