Skip to content

Instantly share code, notes, and snippets.

@iansheridan
Created April 29, 2010 17:05
Show Gist options
  • Save iansheridan/383893 to your computer and use it in GitHub Desktop.
Save iansheridan/383893 to your computer and use it in GitHub Desktop.
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
@iansheridan
Copy link
Author

It turns out that the error was not in the grp object but the wrd as would be revealed by doing a wrd.inspect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment