Skip to content

Instantly share code, notes, and snippets.

@aleksclark
Created August 18, 2011 23:02
Show Gist options
  • Save aleksclark/1155490 to your computer and use it in GitHub Desktop.
Save aleksclark/1155490 to your computer and use it in GitHub Desktop.
class HotspotView
include DataMapper::Resource
property :dm_user_id, Integer, :key => true
property :hotspot_id, Integer, :key => true
belongs_to :dm_user
end
class DmUser
# already taken care of by sinatra-authentication
# include DataMapper::Resource
property :name, String
has n, :hotspot_views, 'HotspotView'
end
ruby-1.9.2-p290 :004 > moo = DmUser.first
=> #<DmUser @id=1 @email="[email protected]" @hashed_password="0e8e4abe778ed9dcecb64c2107de5d4cc7300164" @salt="azanVuk3Tk" @created_at=2011-08-18 00:00:00 -0700 @permission_level=1 @name="bob">
ruby-1.9.2-p290 :005 > hs = HotspotView.first
=> #<HotspotView @dm_user_id=1 @hotspot_id=19>
ruby-1.9.2-p290 :006 > hs.dm_user
=> #<DmUser @id=1 @email="[email protected]" @hashed_password="0e8e4abe778ed9dcecb64c2107de5d4cc7300164" @salt="azanVuk3Tk" @created_at=2011-08-18 00:00:00 -0700 @permission_level=1 @name="bob">
ruby-1.9.2-p290 :007 > moo.hotspot_views
TypeError: can't convert DmUser to Array (DmUser#to_ary gives FalseClass)
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query.rb:56:in `Array'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/
query.rb:56:in `target_conditions'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query/conditions/comparison.rb:474:in `foreign_key_mapping'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:691:in `comparison_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:547:in `conditions_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:649:in `block in operation_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query/conditions/operation.rb:159:in `block in each'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/set.rb:222:in `block in each'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/set.rb:222:in `each_key'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/set.rb:222:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query/conditions/operation.rb:159:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:648:in `operation_statement'
query.rb:56:in `target_conditions'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query/conditions/comparison.rb:474:in `foreign_key_mapping'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:691:in `comparison_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:547:in `conditions_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:649:in `block in operation_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query/conditions/operation.rb:159:in `block in each'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/set.rb:222:in `block in each'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/set.rb:222:in `each_key'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/set.rb:222:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/query/conditions/operation.rb:159:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:648:in `operation_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:546:in `conditions_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:359:in `select_statement'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:137:in `read'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/repository.rb:162:in `read'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/collection.rb:1117:in `lazy_load'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/associations/one_to_many.rb:279:in `lazy_load'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/support/lazy_array.rb:409:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/collection.rb:504:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/collection.rb:976:in `map'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.1.0/lib/dm-core/collection.rb:976:in `inspect'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
ruby-1.9.2-p290 :008 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment