Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created June 30, 2009 12:47
Show Gist options
  • Select an option

  • Save nicolasblanco/138139 to your computer and use it in GitHub Desktop.

Select an option

Save nicolasblanco/138139 to your computer and use it in GitHub Desktop.
def relateds_around
product_id = self.id
organization_id = self.organization.id
Relationship.find(:all) do
any do
all do
left_type == "Product"
left_id == product_id
right_type == "Place"
end
all do
left_type == "Organization"
left_id == organization_id
right_type == "Place"
end
all do
left_type == "Product"
left_id == product_id
right_type == "Event"
end
all do
left_type == "Organization"
left_id == organization_id
right_type == "Event"
end
end
end.map(&:right).delete_if { |r| r.is_a?(Event) && r.past? }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment