Method: Mongoid::Relations::Accessors::ClassMethods#existence_check

Defined in:
lib/mongoid/relations/accessors.rb

#existence_check(name, metadata) ⇒ Class

Adds the existence check for relations.

Examples:

Add the existence check.

Person.existence_check(:name, meta)

Check if a relation exists.

person = Person.new
person.has_game?
person.game?

Parameters:

  • name (String, Symbol)

    The name of the relation.

  • The (Metadata)

    metadata.

Returns:

  • (Class)

    The model being set up.

Since:

  • 3.0.0



198
199
200
201
202
203
204
205
206
# File 'lib/mongoid/relations/accessors.rb', line 198

def existence_check(name, )
  module_eval "    def \#{name}?\n      without_autobuild { !__send__(:\#{name}).blank? }\n    end\n    alias :has_\#{name}? :\#{name}?\n  END\n  self\nend\n"