Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to destroy an many-to-many object and its link in DataMapper/Sinatra/Ruby
    text
    copied!<p>I am a newbie and would appreciate some help on how to resolve this problem. I have tried to follow the documentation in DataMapper and have not found any solutions via Google on how to destroy an object and its corresponding links. Here are the key code segments.</p> <p><strong>The Model</strong></p> <pre><code>class Entity </code></pre> <p>include DataMapper::Resource</p> <p>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 </p> <p>has n, :addresses, :through => Resource has n, :aches has n, :creditcards</p> <p>end</p> <p>class Person &lt; Entity</p> <p>property :birthdate, String property :drivers_license_number, String property :state_issuing_drivers_license, String</p> <p>end</p> <p>class Company &lt; Entity</p> <p>property :dba_name, String property :legal_structure, String property :url, String, :format => :url</p> <p>end</p> <p>class Address</p> <p>include DataMapper::Resource</p> <p>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 :switch_indicator, String property :switch_type, String property :selected_switch_date, Date property :under_contract, Boolean property :contract_end_date, Date </p> <p>has n, :entities, :through => Resource</p> <p>end</p> <p><strong>Object creation and Persistence</strong></p> <pre><code> if session[:base_route].to_s == "residential" #residential processing @entity_id = session[:this_person].inspect @person = Person.get(@entity_id.to_i) @address = Address.new() @address.esid = params[:post][:esid] @address.description = params[:post][:service_location_description] @address.address_line1 = params[:post][:service_address_line1] @address.address_line2 = params[:post][:service_address_line2] @address.city = params[:post][:service_city_name] @address.state = params[:post][:service_state_name] @address.zipcode = params[:post][:service_zip_code] @address.switch_indicator = params[:post][:switch_indicator] @address.switch_type = params[:post][:switch_type] params[:post][:under_contract_checkbox] == "on" ? @under_contract = true : @under_contract = false @address.under_contract = @under_contract @person.addresses &lt;&lt; @address if @person.save </code></pre> <p><strong>Attempted object and link destruction (The link is destroyed, but the address destruction does not work)</strong></p> <pre><code> @entity_id = session[:this_person].inspect address = Address.get(params[:post][:submit].to_i) address.destroy entity = Entity.get(@entity_id) link = entity.address_entities.get(@entity_id, params[:post][:submit]) link.destroy </code></pre> <p>Any tips or suggestions are greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload