Sha256: b578fa5aff387f83a6c790948deb7bcc1efe6eae729da81d3aff3e161add6be1

Contents?: true

Size: 780 Bytes

Versions: 2

Compression:

Stored size: 780 Bytes

Contents

# encoding: UTF-8

module BeerDb
  module Model

class Bookmark < ActiveRecord::Base

  belongs_to :bookmarkable, :polymorphic => true
  belongs_to :user


  ### fix - how to do it with has_many macro? use finder_sql?
  def drinks
    ## todo: check/assert bookmarkable_type == BeerDB::Model::Beer
    Drink.where( user_id: user_id, beer_id: bookmarkable_id )
  end

  def notes
    ## todo: check/assert bookmarkable_type == BeerDB::Model::Beer
    Note.where( user_id: user_id, beer_id: bookmarkable_id )
  end


  ## todo: check: how to handle polymorphic best for getting beer for bookmarkable?
  def beer
    ## todo: check/assert bookmarkable_type == BeerDB::Model::Beer
    Beer.find( bookmarkable_id )
  end

end # class Bookmark

  end # module Model
end # module BeerDb

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
beerdb-0.9.4 lib/beerdb/models/bookmark.rb
beerdb-0.9.3 lib/beerdb/models/bookmark.rb