Chris, If you want indices defined on your tables, you need to require "dm-constraints" and then define your properties like this:
property :unit_id, Integer, :nullable => false, :index => true If you want to establish a unique constraint as well, you will need to property :unit_id, Integer, :nullable => false, :index => true, :unique_index => true That said, I don't know if the association methods (belongs_to, has) support the index property as well, but even if they did, my personal preference would be to specify the index on the property. That's where it belongs in my opinion. Also I have to say that I'm one of those who likes to be explicit about the property *and* the association, i.e. I like to have property :unit_id, Integer, :nullable => false, :index => true, :unique_index => true belongs_to :unit as opposed to simply rely on belongs_to to establish the property as well (which I remember that it didn't do properly, at least some time ago). I just think this is more explicit! cheers snusnu On Mon, Jan 12, 2009 at 09:42, Chris Van Pelt <[email protected]> wrote: > > What's the best practice for defining indexes on associations. I've > been omitting the property declaration for foreign keys. If I want an > index on it (which 99% of the time I expect you would), should I > declare the property along with the association? > > property :unit_id, Integer, :index => true > belongs_to :unit > > or would it be better to do > > belongs_to :unit > index :unit_id > > Also, is it on the road map for auto_upgrade to detect a missing index? > > Chris > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" 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/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
