Forum: Ruby on Rails bug in bubbleshare's Active Record extensions?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Forrest l N. (Guest)
on 2005-12-05 02:53
I'm using add_foreign_key_constraint and remove_foreign_key_constraint
from Bubbleshare's Active Records Extension plugin now to manage the
foreign key relationships I describe in my other recent posting. The
constraints get added within migrations, but I'm running into two
problems (Rails 0.14.3, PostgreSQL db):

1. Dumping the schema doesn't dump the foreign key constraints into
schema.rb. The problem here is that the pattern matching assumes that
both "ON UPDATE" and "ON DELETE" constraints are going to be defined
within the schema, and my schema only defined "ON DELETE". Or at least I
think that's what it is -- adding "ON UPDATE" constraints and then
attempting to dump the schmea also didn't include the constraints, so
maybe this chunk of things is just plain busted.

2. Consider this migration:

class AddConstraints < ActiveRecord::Migration
  def self.up
    add_foreign_key_constraint "tracks", "album_id",  "albums", "id",
:on_delete => :restrict
    add_foreign_key_constraint "tracks", "artist_id", "artists", "id",
:on_delete => :restrict
    add_foreign_key_constraint "albums", "artist_id", "artists", "id",
:on_delete => :restrict
  end

  def self.down
    remove_foreign_key_constraint "tracks", :foreign_key => "album_id"
    remove_foreign_key_constraint "tracks", :foreign_key => "artist_id"
    remove_foreign_key_constraint "albums", :foreign_key => "artist_id"
  end
end

AddConstraints.up works jim dandy -- I can fire up psql and see the
schema correctly modified, using the naming scheme defined in
active_record_extensions.rb. Attempting to down-migrate, though, causes
the system to puke thusly:

> rake --trace environment RAILS_ENV=production VERSION=3 migrate
(in /Users/ogd/Documents/projects/euterpe)
** Invoke environment (first_time)
** Execute environment
** Invoke migrate (first_time)
** Invoke environment
** Execute migrate
rake aborted!
ERROR:  constraint "foreign_keyalbum_id" does not exist
: ALTER TABLE tracks DROP CONSTRAINT foreign_keyalbum_id
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/connection_adapters/abstract_adapter.rb:67:in
`log'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/connection_adapters/postgresql_adapter.rb:113:in
`execute'
./config/../vendor/plugins/ActiveRecordExtensions/lib/active_record_extensions.rb:60:in
`remove_foreign_key_constraint'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:153:in
`send'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:153:in
`method_missing'
./db/migrate//004_add_constraints.rb:9:in `down'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:211:in
`send'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:211:in
`migrate'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:206:in
`each'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:206:in
`migrate'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:177:in
`down'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:166:in
`migrate'
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/tasks/databases.rake:3
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/tasks/databases.rake:2:in
`call'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:180:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/bin/rake:7
/usr/bin/rake:18:in `load'
/usr/bin/rake:18

The dispatch in method_missing is sending the message to the wrong
module within the plugin (it should be to SchemaStatements, not
AbstractAdapter). I'm at a loss as to how to fix that, as I'm still
figuring out how ActiveRecord is wired internally. Anyone know how to
fix? Thanks!

F
This topic is locked and can not be replied to.