Created
December 21, 2009 03:27
-
-
Save kematzy/260751 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
| ## DataMapper 0.10.2 & ASSOCIATIONS | |
| # | |
| # I'm working on a Client model, and need to track the Nationality of the Client, | |
| # but don't really want to create an un-necessary Nationality model, when I theoretically | |
| # can use the existing Country model. | |
| # | |
| # All the variations I've tried causes a similar error: | |
| # | |
| # Cannot add a NOT NULL column with default value NULL (DataObjects::SyntaxError) | |
| # | |
| # How to overcome this error ?? | |
| # | |
| # Using SQLite3 as the DB | |
| # | |
| # | |
| # /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:124:in `execute_non_query': Cannot add a NOT NULL column with default value NULL (DataObjects::SyntaxError) | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:124:in `upgrade_model_storage' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:118:in `map' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:118:in `upgrade_model_storage' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:269:in `with_connection' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:117:in `upgrade_model_storage' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:1302:in `upgrade_model_storage' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:1373:in `auto_upgrade!' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:45:in `send' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:45:in `repository_execute' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model/descendant_set.rb:33:in `each' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/model/descendant_set.rb:33:in `each' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:44:in `repository_execute' | |
| # from /Library/Ruby/Gems/1.8/gems/dm-core-0.10.2/lib/dm-core/migrations.rb:27:in `auto_upgrade!' | |
| class Client | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :name, String | |
| # # The nationality of the client, taken from the Country model | |
| property :nationality, String, :default => "MY", :length => 2 | |
| ## ASSOCIATIONS | |
| # a Client can only have one nationality (in this case at least) | |
| # has 1, :nationality, 'Country' | |
| # has 1, :nationality, :model => 'Country' #, :foreign_key => :code | |
| belongs_to :nationality, :model => 'Country', :foreign_key => :code | |
| # belongs_to :nationality, :model => 'Country'#, :child_key => :code | |
| end | |
| class Country | |
| include DataMapper::Resource | |
| # The two letter unique code for the country | |
| property :code, String, :key => true | |
| # The name of the country | |
| property :name, String | |
| ## ASSOCIATIONS | |
| has n, :clients | |
| end #/ Country |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment