On 7 Oct 2008, at 15:43, gaveeno wrote:
> > Rob - you mentioned that you should have indexes on your *_id columns > if they're used in has_many relationships. When I created my > migrations for tables containing *_id columns, I set these columns up > like in the following example: > > create_table :branches do |t| > t.integer :company_id, :null => false, :options => "CONSTRAINT > fk_branch_company REFERENCES companies(id)" > ... > > How would I add an index to an existing column? And, for future > tables that I'll be creating, how would I set up a new column with an > index? > add_index adds indices. If you're using mysql than creating a foreign key constrain implicitly creates an index. Fred > Thanks! > Gavin > > > On Oct 6, 5:13 pm, Rob Biedenharn <[EMAIL PROTECTED]> wrote: >> On Oct 6, 2008, at 5:06 PM, elioncho wrote: >> >>> Hello, >> >>> I have a dilemma. Should I create foreign keys on my database or >>> should I let the app models do all the work? >> >>> Thanks, >> >>> Elioncho >> >> If the Rails app is the only thing hitting the database, then let >> ActiveRecord handle it. >> >> If you're paranoid or there are other apps updating the database, >> then >> go for the safety-net. >> >> In any case, you certainly want indexes on your *_id columns if there >> is a has_many that uses it. (I.e., on the bars.foo_id column if Foo >> has_many :bars) >> >> -Rob >> >> Rob Biedenharn http://agileconsultingllc.com >> [EMAIL PROTECTED] > > --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

