sdawes sdawes -5 years ago 123
Ruby Question

Data Mapper Associations - what code?

ive looked through the DataMapper docs but am struggling to see how to do this. I have two tables and I simply wish to add the 'handle' attribute from the User table, as a column to the Peeps table - as per below?

enter image description here

Answer Source

Doc: Customizing Associations section.

class User
  has n, :peeps, 'Peep',
    :parent_key => [ :handle ],      # local to this model (User)
    :child_key  => [ :user_handle ]  # in the remote model (Peep)

class Peep
  belongs_to :user, 'User',
    :parent_key => [ :handle ],      # in the remote model (Peep)
    :child_key  => [ :user_handle ]  # local to this model (User)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download