
dm-constraints does not load models correct to infer key
Reported by Xavier Shay | December 15th, 2010 @ 08:58 PM
I don't really know how to describe this bug, except in code:
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-constraints'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test
class Post
include DataMapper::Resource
property :id, Serial
belongs_to :author
end
class User
include DataMapper::Resource
property :id, Serial
end
class Author
include DataMapper::Resource
belongs_to :user, :key => true, :child_key => [:id]
has n, :posts
end
DataMapper.finalize
DataMapper.auto_migrate!
Fails with:
~ (0.000255) ALTER TABLE "posts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENCES "authors" () ON DELETE NO ACTION ON UPDATE NO ACTION
~ ERROR: syntax error at or near ")"
LINE 1: ...ts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENC...
^
(code: 16801924, sql state: 42601, query: ALTER TABLE "posts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENCES "authors" () ON DELETE NO ACTION ON UPDATE NO ACTION, uri: postgres://localhost/test)
/Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:63:in `execute_non_query': ERROR: syntax error at or near ")" (DataObjects::SyntaxError)
LINE 1: ...ts" ADD CONSTRAINT "posts_author_fk" FOREIGN KEY () REFERENC...
^
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:63:in `block in execute'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:260:in `with_connection'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:61:in `execute'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/adapters/dm-do-adapter.rb:64:in `create_relationship_constraint'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:51:in `block in execute_each_relationship'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:50:in `each_value'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:50:in `execute_each_relationship'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:43:in `auto_migrate_up_constraints!'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-migrations-1.0.2/lib/dm-migrations/auto_migration.rb:45:in `block in repository_execute'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:68:in `block in each'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:67:in `each'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-core-1.0.2/lib/dm-core/support/descendant_set.rb:67:in `each'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-migrations-1.0.2/lib/dm-migrations/auto_migration.rb:44:in `repository_execute'
from /Users/xavier/.rvm/gems/ruby-1.9.2-p0/gems/dm-constraints-1.0.2/lib/dm-constraints/migrations.rb:12:in `auto_migrate!'
from dm-load-order.rb:32:in `<main>'
The work around is to move the Post definition below the Author definition (or if using autoloading and rails, add a reference to Author at the top of the post.rb file to force it to be loaded before the rest of the file is run)
No comments found
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »