Skip to content

Instantly share code, notes, and snippets.

@gerhard
Created December 3, 2008 01:23
Show Gist options
  • Select an option

  • Save gerhard/31381 to your computer and use it in GitHub Desktop.

Select an option

Save gerhard/31381 to your computer and use it in GitHub Desktop.
class PurchaseOrder < ActiveRecord::Base
has_one :address_linking, :as => :address_linkable, :dependent => :destroy
has_one :address, :through => :address_linking
end
class AddressLinking < ActiveRecord::Base
belongs_to :address
belongs_to :address_linkable, :polymorphic => true
end
class Address < ActiveRecord::Base
has_many :address_linkings
end
def update
@purchase_order = PurchaseOrder.find(params[:id])
if @purchase_order.update_attributes(params[:purchase_order])
redirect_to_index("Purchase Order was successfully updated")
else
render :action => "edit"
end
end
Processing Admin::PurchaseOrderController#update (for 127.0.0.1 at 2008-12-08 20:14:35) [PUT]
Session ID: 3bf4103250cf261cdbc4356c77c2b62a
Parameters: {"commit"=>"Update Purchase Order", "action"=>"update", "_method"=>"put", "id"=>"1", "purchase_order"=>{"supplier_id"=>"1", "user_id"=>"1", "address"=>{"address1"=>"NEW PURCHASE ORDER ADDRESS", "address2"=>"", "postcode"=>"", "county"=>"", "id"=>"1", "town"=>""}}, "controller"=>"admin/purchase_order"}
User Columns (1.7ms) SHOW FIELDS FROM `users`
User Load (0.3ms) SELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
PurchaseOrder Columns (1.3ms) SHOW FIELDS FROM `purchase_orders`
PurchaseOrder Load (0.5ms) SELECT * FROM `purchase_orders` WHERE (`purchase_orders`.`id` = 1)
AddressLinking Columns (2.3ms) SHOW FIELDS FROM `address_linkings`
AddressLinking Load (0.5ms) SELECT * FROM `address_linkings` WHERE (`address_linkings`.address_linkable_id = 1 AND `address_linkings`.address_linkable_type = 'PurchaseOrder') LIMIT 1
SQL (0.1ms) BEGIN
##########
##### WHY IS THIS USING THE Address.id (the class' id)??
##########
>>>>> AddressLinking Update (0.2ms) UPDATE `address_linkings` SET `address_id` = 32574510 WHERE `id` = 456
SQL (0.5ms) COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment