Skip to content

Commit

Permalink
initial Mongoid associations added
Browse files Browse the repository at this point in the history
  • Loading branch information
zefer committed Feb 28, 2011
1 parent 7468c4e commit e909f7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/active_cart/items/mongoid_item.rb
Expand Up @@ -2,18 +2,22 @@ module ActiveCart
module Items

class MongoidItem
attr_accessor :id, :name, :price
include ActiveCart::Item

def ==(item)
self._id == item.id
include Mongoid::Document
include Mongoid::Timestamps

embedded_in :cart, :class_name => "ActiveCart::StorageEngines::MongoidStorage", :inverse_of => :items

field :name
field :price

def quantity
@quantity || 0
end

def initialize(id, name, price)
@id = id
@name = name
@price = price
def quantity=(quantity)
@quantity = quantity
end

end

end
Expand Down
2 changes: 2 additions & 0 deletions lib/active_cart/storage_engines/mongoid_storage.rb
Expand Up @@ -5,6 +5,8 @@ class MongoidStorage
include Mongoid::Document
include Mongoid::Timestamps
include ActiveCart::CartStorage

embeds_many :items, :class_name => "ActiveCart::Items::MongoidItem"

def invoice_id
self._id
Expand Down

0 comments on commit e909f7e

Please sign in to comment.