schemaplus / schema_plus_foreign_keys Goto Github PK
View Code? Open in Web Editor NEWExtended support for foreign keys in ActiveRecord
License: MIT License
Extended support for foreign keys in ActiveRecord
License: MIT License
I'm having a problem using this gem with Rails 5.1.0.beta1. I open an issue there rails/rails#28192, but I think the problem is with schema_plus_foreign_keys
While using this gem, when I execute Event.last.administrators.to_sql
in a class like this:
class Event < ApplicationRecord
has_and_belongs_to_many :administrators, class_name: User
end
I get the following:
"SELECT \"users\".* FROM \"users\" WHERE \"users\".\"event_id\" = 1"
Instead of:
"SELECT \"users\".* FROM \"users\" INNER JOIN \"events_users\" ON \"users\".\"id\" = \"events_users\".\"user_id\" WHERE \"events_users\".\"event_id\" = 1"
Its not possible to add options when using the new syntax of add_foreign_key
i.e. this fails:
add_foreign_key 'archive.sub_engagement_logs', 'site.sites', name: 'some lol'
t.references
always creates an integer column. But that won't work as a foreign key if the referenced table's id isn't an integer. For example, it might be a uuid
(see Rails 4 Postgres UUID Primary Key Guide
t.references
could possibly look up the primary key column type of the table being referenced, and act accordingly.
Hi,
Just seeing if this project is still active and accepting PRs?
We use various schema_plus*
gems in our Rails 4.2 apps, but are looking at upgrading to Rails 5.2, which isn't currently supported.
I can see there is PR #15 for Rails 5.2 support, but that just changes the gemspec. Would you be open to a PR for Rails 5.2 support?
Thanks!
Joe.
The readme currently says:
SchemaPlus::ForeignKey.setup do |config|
config.on_update = :cascade # default is nil, meaning use default dbms behavior
config.on_delete = :nullify # default is nil, meaning use default dbms behavior
end
But I think it should be:
SchemaPlus::ForeignKeys.setup do |config|
config.on_update = :cascade # default is nil, meaning use default dbms behavior
config.on_delete = :nullify # default is nil, meaning use default dbms behavior
end
Note the added "s" on end of SchemaPlus::ForeignKeys.
With Rails 7.1 out it would be good to raise this pin on this and related gems. Ref: SchemaPlus/schema_dev#31
Hi,
Your latest release (0.1.5) causes an error when calling 'remove_foreign_key' in migrations. Requiring 'its-it' explicitly in Gemfile fixes it, so I guess it just needs to be required somewhere.
undefined local variable or method `its' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x007fc48ce854b0>
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/schema_plus_foreign_keys-0.1.5/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb:109:in `get_foreign_key_name'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/schema_plus_foreign_keys-0.1.5/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb:123:in `remove_foreign_key_sql'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/schema_plus_foreign_keys-0.1.5/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb:70:in `remove_foreign_key'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:665:in `block in method_missing'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:634:in `block in say_with_time'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:634:in `say_with_time'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:654:in `method_missing'
/Users/nedforce/projects/my_project/db/migrate/20160530151530_remove_foreign_key_from_permit_archives.rb:8:in `up'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:611:in `exec_migration'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:592:in `block (2 levels) in migrate'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:591:in `block in migrate'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:590:in `migrate'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:773:in `migrate'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:1003:in `block in execute_migration_in_transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:1049:in `block in ddl_transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/transactions.rb:220:in `transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:1049:in `ddl_transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:1002:in `execute_migration_in_transaction'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:964:in `block in migrate'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:960:in `each'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:960:in `migrate'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:828:in `up'
/Users/nedforce/.rvm/gems/ruby-2.2.2@devcms/gems/activerecord-4.2.6/lib/active_record/migration.rb:806:in `migrate'
Specifying
create_table :course_assessment_question_multiple_response_options do |t|
t.references :question,
null: false,
foreign_key: {
name: :fk__course_assessment_multiple_response_option_question,
references: :course_assessment_question_multiple_responses
}
end
errors with a name too long error. This works:
create_table :course_assessment_question_multiple_response_options do |t|
t.references :question,
null: false,
index: {
name: :fk__course_assessment_multiple_response_option_question,
},
foreign_key: {
references: :course_assessment_question_multiple_responses
}
end
Hi,
My app has a very large table (lets call it articles
) and another slightly smaller table called comments
. I added a migration to rename the comments table to messages
and was very surprised to see our app blow up when the migration started hanging. After some research it appeared that a constraint was being removed and re-added here. I understand the constraint is being removed and re-added because it cannot be renamed in all cases, but I would expect there to be some way to disable this. Since the following migration:
def change
rename_table :comments, :messages
end
Appears to have no side affects. Changing the name of the constraints isn't a necessity so it would be nice to turn this off.
Also, in PostgreSQL versions later than 9.2, it's possible to rename a constraint:
alter table messages rename constraint fk_comments_article_id to fk_messages_article_id
Is it possible to have a configuration option to enable constraint renaming or at the very least, disable removing and re-creating these constraints?
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.