Created
July 27, 2009 13:14
-
-
Save tpitale/156248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'dm-core' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'sqlite3::memory:') | |
| class Sale | |
| include DataMapper::Resource | |
| property :id, Serial | |
| belongs_to :user | |
| has n, :sale_items | |
| has n, :items, :through => :sale_items | |
| end | |
| class SaleItem | |
| include DataMapper::Resource | |
| property :id, Serial | |
| belongs_to :sale | |
| belongs_to :item | |
| end | |
| class Item | |
| include DataMapper::Resource | |
| property :id, Serial | |
| has n, :sale_items | |
| end | |
| class User | |
| include DataMapper::Resource | |
| property :id, Serial | |
| has n, :sales | |
| has n, :sale_items, :through => :sales | |
| # has n, :items, :through => :sale_items | |
| end | |
| Sale.auto_migrate! | |
| # Sale is fine here | |
| puts Sale.new.inspect | |
| DataMapper.auto_migrate! | |
| # Sale now has sale_item_id | |
| puts Sale.new.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment