Hello, I had an application on Rails 1.2 or 1.1 (don''t remember). Now I have updated it to 2.1. I had a migrations_helper.rb in the Libs directory which defined foreign_key and drop_foreign_key methods. But now migrate task doesn''t find them. Have I to include this directory somewhere with Rails 2.1? Doesn''t it work as always? Could I use another thing to declare foreign keys without having a class made by myself? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Any suggestion? On Jul 4, 6:17 pm, Eduardo Yáñez Parareda <eduardo.ya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I had an application on Rails 1.2 or 1.1 (don''t remember). Now I have > updated it to 2.1. > > I had a migrations_helper.rb in the Libs directory which defined > foreign_key and drop_foreign_key methods. But now migrate task doesn''t > find them. Have I to include this directory somewhere with Rails 2.1? > Doesn''t it work as always? > > Could I use another thing to declare foreign keys without having a > class made by myself?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Eduardo Yáñez Parareda wrote:> Hello, > > I had an application on Rails 1.2 or 1.1 (don''t remember). Now I have > updated it to 2.1. > > I had a migrations_helper.rb in the Libs directory which defined > foreign_key and drop_foreign_key methods. But now migrate task doesn''t > find them. Have I to include this directory somewhere with Rails 2.1? > Doesn''t it work as always? > > Could I use another thing to declare foreign keys without having a > class made by myself?Depends how your code works, but I imagine you''re extending the existing rails migration classes. so I''d suggest doing a "require ''migration_extensions''" at the top of the migration file. -- 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
> Depends how your code works, > but I imagine you''re extending the existing rails migration classes. > > so I''d suggest doing a "require ''migration_extensions''" at the top of > the migration file.Yes, I already do it!... This is my helper: module MigrationHelpers def foreign_key(from_table, from_column, to_table) constraint_name = "fk_#{from_table}_#{from_column}" execute %{alter table #{from_table} add constraint #{constraint_name} foreign key (#{from_column}) references #{to_table} (id)} end def drop_foreign_key(table, foreign_key) execute %{alter table #{table} drop foreign key #{foreign_key}} end end and this is my migration class: require ''migration_helpers'' class CreateProjectUserRoles < ActiveRecord::Migration def self.up create_table :project_user_roles do |t| t.references :project t.references :user t.string :role, :null => false t.timestamps end foreign_key :project_user_roles, :user_id, :users foreign_key :project_user_roles, :project_id, :projects end def self.down drop_foreign_key :project_user_roles, :fk_project_user_roles_user_id drop_foreign_key :project_user_roles, :fk_project_user_roles_project_id drop_table :project_user_roles end end Helper is into ''lib'' directory, so I think it is loaded when server starts. Well Indeed it worked in RoR 1.2. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, I''m feeling stupid.... I forgot to extend the migration class in order to use the foreign key Module... On Jul 10, 6:04 pm, Eduardo Yáñez Parareda <eduardo.ya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Depends how your code works, > > but I imagine you''re extending the existing rails migration classes. > > > so I''d suggest doing a "require ''migration_extensions''" at the top of > > the migration file. > > Yes, I already do it!... > > This is my helper: > > module MigrationHelpers > def foreign_key(from_table, from_column, to_table) > constraint_name = "fk_#{from_table}_#{from_column}" > execute %{alter table #{from_table} > add constraint #{constraint_name} > foreign key (#{from_column}) > references #{to_table} (id)} > end > > def drop_foreign_key(table, foreign_key) > execute %{alter table #{table} drop foreign key #{foreign_key}} > end > end > > and this is my migration class: > > require ''migration_helpers'' > > class CreateProjectUserRoles < ActiveRecord::Migration > def self.up > create_table :project_user_roles do |t| > t.references :project > t.references :user > t.string :role, :null => false > > t.timestamps > end > foreign_key :project_user_roles, :user_id, :users > foreign_key :project_user_roles, :project_id, :projects > end > > def self.down > > drop_foreign_key :project_user_roles, :fk_project_user_roles_user_id > > drop_foreign_key :project_user_roles, :fk_project_user_roles_project_id > drop_table :project_user_roles > end > end > > Helper is into ''lib'' directory, so I think it is loaded when server > starts. Well Indeed it worked in RoR 1.2.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---