sdawes sdawes - 4 months ago 7
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


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)