datamapper / dm-constraints Goto Github PK
View Code? Open in Web Editor NEWDataMapper plugin constraining relationships
Home Page: http://datamapper.org/
License: MIT License
DataMapper plugin constraining relationships
Home Page: http://datamapper.org/
License: MIT License
constraints hooks always runs first. They should executes last, after all custom hooks, defined by user, exept bang! methods
They recently added foreign key support. http://www.sqlite.org/releaselog/3_6_19.html
Created by FreakGuard - 2010-09-06 18:04:31 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1399
Would anyone be interested in SQLite3 support for constraints? I have some code written using triggers which I could clean up and submit if there was sufficient interest.
Created by Simon Harris - 2009-09-21 14:02:32 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1053
please clone this gist and run "bundle install" then run the ruby file (edit your mysql user and pass if needed)
git://gist.github.com/1381221.git
then uncomment the belongs_to line and run again, it should reproduce the error
gist link: https://gist.github.com/1381221
lighthouse issue:
I'm currently running MySQL 5.1.41 and I'm having problems using this gem.
I'm no expert but I'm guessing it has to do with the way names are quoted.
For example here is a debug output of the first query that fails with mysql complaining about the syntax.
SELECT COUNT(*) FROM "information_schema"."table_constraints" WHERE "constraint_type" = 'FOREIGN KEY' AND "table_schema" = 'ultra_dev' AND "table_name" = 'subscriptions' AND "constraint_name" = 'subscriptions_account_fk'
As you can see the names are quoted using normal double quotes and when they are replaced by ` the query runs ok.
Example that works
SELECT COUNT(*) FROM information_schema
.table_constraints
WHERE constraint_type
= 'FOREIGN KEY' AND table_schema
= 'ultra_dev' AND table_name
= 'subscriptions' AND constraint_name
= 'subscriptions_account_fk'
This is probably why dm-mysql-adapter has some special code to handle this.
http://github.com/datamapper/dm-mysql-adapter/blob/master/lib/dm-mysql-adapter/adapter.rb#L34-36
Is this something that could be fixed on this end or do I have something configured wrong?
I attached a test case...
Created by Fabian - 2008-12-10 14:09:59 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/705
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)
Created by Xavier Shay - 2010-12-16 02:58:14 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1457
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.