Class: NoSE::Fields::ForeignKeyField

Inherits:
IDField show all
Defined in:
lib/nose/model/fields.rb

Overview

Field holding a foreign key to another entity

Constant Summary

Constants inherited from Field

NoSE::Fields::Field::TYPE

Instance Attribute Summary collapse

Attributes inherited from Field

#name, #parent, #primary_key, #size

Instance Method Summary collapse

Methods inherited from IDField

#random_value, value_from_string

Methods inherited from Field

#*, #==, #hash, #id, #random_value, #to_color, #to_s, value_from_string

Methods included from Supertype

included

Constructor Details

#initialize(name, entity, **options) ⇒ ForeignKeyField

Returns a new instance of ForeignKeyField.



278
279
280
281
282
283
# File 'lib/nose/model/fields.rb', line 278

def initialize(name, entity, **options)
  @relationship = options.delete(:relationship) || :one
  super(name, **options)
  @primary_key = false
  @entity = entity
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.



275
276
277
# File 'lib/nose/model/fields.rb', line 275

def entity
  @entity
end

#relationshipObject (readonly)

Returns the value of attribute relationship.



275
276
277
# File 'lib/nose/model/fields.rb', line 275

def relationship
  @relationship
end

#reverseObject

Returns the value of attribute reverse.



276
277
278
# File 'lib/nose/model/fields.rb', line 276

def reverse
  @reverse
end

Instance Method Details

#cardinalityFixnum

The number of entities associated with the foreign key, or a manually set cardinality

Returns:

  • (Fixnum)


288
289
290
# File 'lib/nose/model/fields.rb', line 288

def cardinality
  @entity.count || super
end