Skip to content

Instantly share code, notes, and snippets.

@c-lliope
Created December 14, 2014 03:59
Show Gist options
  • Save c-lliope/6313e88011d1c26d4610 to your computer and use it in GitHub Desktop.
Save c-lliope/6313e88011d1c26d4610 to your computer and use it in GitHub Desktop.
class PlantBucketAssignment
belongs_to :plant
belongs_to :bucket
end
class Bucket
has_many :plant_bucket_assignments
has_many :plants, through: :plant_bucket_assignments
def current_plant
plant.sort_by(:created_at).last
end
end
class Plant
has_many :plant_bucket_assignments
has_many :buckets, through: :plant_bucket_assignments
def current_bucket
buckets.sort_by(:created_at).last
end
def current_bucket=(bucket)
buckets << bucket
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment