Created
October 19, 2009 16:12
-
-
Save alx/213486 to your computer and use it in GitHub Desktop.
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 User | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
property :created_at, DateTime | |
has n, :tags | |
end | |
class Tag | |
include DataMapper::Resource | |
property :id, Serial | |
property :created_at, DateTime | |
property :updated_at, DateTime | |
property :credits, Integer, :default => 0 | |
belongs_to :user | |
has n, :products | |
def has_credit? | |
remaining_credit > 0 | |
end | |
def remaining_credit | |
self.credits - products_value | |
end | |
def products_value | |
value = 0 | |
self.products.each do |product| | |
value += product.value | |
end | |
return value | |
end | |
end | |
class Product | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
property :created_at, DateTime | |
property :value, Integer, :default=>1 | |
validates_present :name | |
belongs_to :user | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment