Hobo Cookbook

View Source

Question: How do I specify primary and foreign keys for legacy tables?

Asks smvanbru
I have live legacy tables that I'd like to access with Hobo.

As such, I'd like to create models around them, but not modify them. One thing I need to do in the models, is specify what the the primary key and foreign keys are. How do I do this with Hobo models?

Thanks!

Discussion

  • Thanks to guys on the email list, I've figured it out.

    For Primary keys, add
    set_primary_key "ID"
    to each model file.

    For Foreign keys, you need to add
    :foreign_key => 'ParentID'
    to both the has_many and the belongs_to sections of the parent and child models.