Created
June 23, 2011 04:05
-
-
Save gamov/1041878 to your computer and use it in GitHub Desktop.
Getting a different model from an association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shipment | |
has_many :shipping_items, :inverse_of => :shipment, :dependent => :destroy do | |
def linked_po_ids | |
joins(:purchased_item => :purchase_order).select('DISTINCT purchase_orders.id AS po_id').map{|si| si.po_id} | |
def linked_pos | |
? #how to return the purchase orders (objects) ? | |
end | |
end | |
def linked_pos | |
PurchaseOrder.joins(:purchased_items => :shipping_items).where(:shipping_items => {:shipment_id => self.id}).select('DISTINCT purchase_orders.*') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment