I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack 0.8.7, mysql 5.1.41) I has my_app/lib/migration_helpers.rb file: module MigrationHelpers def self.foreign_key(from_table, from_column, to_table) constraint_name = "fk_#{from_table}_#{to_table}" execute %{alter table #{from_table} add constraint #{constraint_name} foreign key (#{from_column}) references #{to_table}(id) }.... end In my_app/db/migrate/001_create_airports.rb: require "migration_helpers" class CreateAirports < ActiveRecord::Migration extend MigrationHelpers def self.up create_table (:airports, :options => "ENGINE=InnoDB") do |t| t.integer :country_id, :null => false #foreign key t.string :code, :null => false, :limit => 3 t.string :name, :null => false, :limit => 45 t.timestamps end foreign_key(:airports, :country_id, :countries) end def self.down drop_table :airports end end When I rake db:migration it got this error: -- create_table(:airports, {:options=>"ENGINE=InnoDB"}) -> 0.0156s -- foreign_key(:airports, :country_id, :countries) rake aborted! undefined method `foreign_key'' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x5cf4d50> What did I miss? Thank you -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 9, 6:38 pm, "Tau C." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack > 0.8.7, mysql 5.1.41) > > I has my_app/lib/migration_helpers.rb file: > module MigrationHelpers > def self.foreign_key(from_table, from_column, to_table) > constraint_name = "fk_#{from_table}_#{to_table}" >this should probably be just def foreign_key(...) Fred> execute %{alter table #{from_table} > add constraint #{constraint_name} > foreign key (#{from_column}) > references #{to_table}(id) > > }.... > end > > In my_app/db/migrate/001_create_airports.rb: > > require "migration_helpers" > class CreateAirports < ActiveRecord::Migration > extend MigrationHelpers > > def self.up > create_table (:airports, :options => "ENGINE=InnoDB") do |t| > t.integer :country_id, :null => false #foreign key > t.string :code, :null => false, :limit => 3 > t.string :name, :null => false, :limit => 45 > > t.timestamps > end > foreign_key(:airports, :country_id, :countries) > end > > def self.down > drop_table :airports > end > end > > When I rake db:migration it got this error: > -- create_table(:airports, {:options=>"ENGINE=InnoDB"}) > -> 0.0156s > -- foreign_key(:airports, :country_id, :countries) > rake aborted! > undefined method `foreign_key'' for > #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x5cf4d50> > > What did I miss? > > Thank you > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #960395:> On Nov 9, 6:38pm, "Tau C." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack >> 0.8.7, mysql 5.1.41) >> >> I has my_app/lib/migration_helpers.rb file: >> module MigrationHelpers >> def self.foreign_key(from_table, from_column, to_table) >> constraint_name = "fk_#{from_table}_#{to_table}" >> > > this should probably be just def foreign_key(...) > > FredIt is working!. You''re a live saver, Thank you so much for your time. Tau. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.