Method: Sohm::Model.set

Defined in:
lib/sohm.rb

.set(name, model) ⇒ Object

Declare an Sohm::Set with the given name.

Example:

class User < Sohm::Model
  set :posts, :Post
end

u = User.create
u.posts.empty?
# => true

Note: You can’t use the set until you save the model. If you try to do it, you’ll receive an Sohm::MissingID error.



657
658
659
660
661
662
663
664
665
# File 'lib/sohm.rb', line 657

def self.set(name, model)
  track(name)

  define_method name do
    model = Utils.const(self.class, model)

    Sohm::MutableSet.new(key[name], model.key, model)
  end
end