There is an entity/company table and an address table.  There can only be 
one entry in the address table per address since the esid field is defined 
as unique.  I am able to store multiple unique addresses for a given 
entity.  However, if the address is associated with a different entity, the 
save fails. DataMapper has created a table called "address_entities" which 
shows the links between an entity and and an address. How do I make entries 
to this table to link the single address entry to multiple entities?  The 
pertinent data and code is below.  Any assistance would be greatly 
appreciated.

       @entity_id = session[:this_company].inspect
        @company = Company.get(@entity_id.to_i)
        @company.addresses << @address
        if @company.save



class Entity
  
  include DataMapper::Resource
  
  property :entity_id,        Serial
  property :full_legal_name,  String
  property :tax_id,           String
  property :phone_number,     String
  property :fax_number,       String
  property :cell_number,      String
  property :email,            String, :unique => true, :format => 
:email_address
  property :alt_email,        String
  property :is_active,        Boolean
  property :created_at,       DateTime
  property :created_by,       String
  property :updated_at,       DateTime
  property :updated_by,       String
  property :auto_pay,         Boolean
  property :use_ach,          Boolean
  property :prefix,                        String
  property :first_name,                    String
  property :middle_name,                   String
  property :last_name,                     String
  property :suffix,                        String
  property :referral_code,                  String
  property :login_name,                    String, :unique => true
  property :hashed_password,               String, :length => 200
  property :salt,                          String
  property :permission_level,              Integer
  property :title,                         String
  property :greeting,                      String
  property :preferred_name,                String
  property :preferred_language,            String
  property :security_question,             String
  property :security_answer,               String
  property :signature_font,                String
  property :auth1_checkbox, Boolean
  property :auth2_checkbox, Boolean
  property :auth3_checkbox, Boolean
  property :auth4_checkbox, Boolean
  property :auth5_checkbox, Boolean
  property :auth6_checkbox, Boolean
  property :digital_signature, String
  property :date_signed, DateTime
  property :signatory_ip, String
  property :signatory_title, String 
  
  has n, :addresses, :through => Resource
  has n, :aches
  has n, :creditcards

end

class Person < Entity
  
  property :birthdate,                     String
  property :drivers_license_number,        String
  property :state_issuing_drivers_license, String

end

class Company < Entity
  
  property :dba_name,        String
  property :legal_structure, String
  property :url,             String, :format => :url
  
end

class Address
  
  include DataMapper::Resource
  
  property :address_id,        Serial
  property :esid,              String, :unique => true
  property :description,       String
  property :address_line1,     String
  property :address_line2,     String
  property :city,              String
  property :state,             String
  property :zipcode,           String
  property :country,           String
  property :meter_number,      String
  property :meter_type,        String
  property :meter_status,      String
  property :meter_status_date, DateTime
  property :updated_by,        String
  property :tax_exempt,        Boolean
  property :current_provider,  String
  property :switch_indicator,  String
  property :switch_type,       String
  property :selected_switch_date, Date
  property :under_contract,    Boolean
  property :contract_end_date, Date  
  
  has n, :entities, :through => Resource

end

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/datamapper/-/tyNZfjR3U8wJ.
To post to this group, send email to datamapper@googlegroups.com.
To unsubscribe from this group, send email to 
datamapper+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to