SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Defining Relationships in Ruby

    Hello,
    Im new to the world of ruby, im currently designing a small clinical information app using ruby, i have designed my tables and relationships by hand but im having some trouble passing it to the rails world, can someone give me a help please?

    Thanks

    Table Patient,
    id_number:string, id_type:string, name:string, common_name:string, address:string, tax_number:string, birth_date:string, sex:string, mobile_phone:string, home_phone:string, work_phone:string, email:string

    Table Postal,
    code:string
    name:string

    Table Entity,
    name:string
    number:string
    expiry_date:date

    Table Profession,
    name:string

    Relationships,

    Patient has_one ostal, has_one :entity, has_one rofession
    Postal has_and_belongs_to_many atients
    Entities belongs_to atient
    Profession has_and_belongs_to_many atients

    Once again many thanks

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rails by default expects there to be an id field in every table (except has_and_belongs_to_many join tables). It uses the id field to set up the relationships. You can over-ride this behaviour by defining foreign_key and primary_key in your belongs_to or has_many declarations. However, it is usually easier to just use ids.

    The id should be a self-incrementing integer field.

    The Rails App explains what is required reasonably well:

    http://api.rubyonrails.org/


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •