Created
April 29, 2010 17:05
-
-
Save iansheridan/383893 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 Keygroup | |
include DataMapper::Resource | |
has n, :keywords, :through => Resource | |
has n, :categories, :through => Resource | |
property :id, Serial | |
property :name, String | |
property :description, Text | |
property :created_at, DateTime | |
property :updated_at, DateTime | |
after :create, :create_master_keyword | |
def create_master_keyword | |
key = Keyword.new | |
key.name = self.name | |
key.master = true | |
key.keygroups << self | |
raise RuntimeError, "Keygroup's Master Keyword has not been saved!" unless key.save | |
end | |
end | |
class Keyword | |
include DataMapper::Resource | |
has n, :keygroups, :through => Resource | |
has n, :images, :through => Resource | |
has 1, :store | |
has 1, :example | |
property :id, Serial | |
property :name, String | |
property :master, Boolean, :default => false | |
property :created_at, DateTime, :writer => :private | |
property :updated_at, DateTime, :writer => :private | |
def master? | |
self.master | |
end | |
end | |
grp = Keygroup.get(1) | |
wrd = Keyword.get(1) | |
grp.keywords << wrd | |
grp.save # returns false | |
grp.errors.each{|e| puts e } # empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It turns out that the error was not in the grp object but the wrd as would be revealed by doing a wrd.inspect