Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'pp'
- require 'do_sqlite3'
- require 'dm-core'
- DataMapper.setup(:default, 'sqlite3:///tmp/bs.db')
- class Infestation
- include DataMapper::Resource
- property :id, Serial
- belongs_to :sheep
- belongs_to :flea
- end
- class Sheep
- include DataMapper::Resource
- property :id, Serial
- property :name, String, :lazy => false
- has n, :infestations
- has n, :fleas, :through => :infestations
- end
- class Flea
- include DataMapper::Resource
- property :id, Serial
- property :name, String, :lazy => false
- has n, :infestations
- has n, :sheeps, :through => :infestations
- end
- DataMapper.auto_migrate!
- DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, 0)
- # now for the interesting stuff
- s = Sheep.create(:name => 'Shaun')
- s.fleas.new(:name => 'Fred')
- s.fleas.new(:name => 'Frank')
- s.save or raise "argh?"
- @s = Sheep.first
- puts "==========================="
- puts "Flea.repositories is normal"
- pp Flea.repositories
- puts "@properties before we break it"
- pp Flea.instance_variable_get("@properties")
- puts "This screws up @properties on Flea"
- (@s.fleas(:name => "Fred") - @s.fleas(:name => "Frank")).to_a
- puts "This should not have the Repository as a key"
- pp Flea.instance_variable_get("@properties")
- puts "And accessing repositories will raise"
- Flea.repositories # This raises
Add Comment
Please, Sign In to add comment