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.



289
290
291
292
293
294
# File 'lib/nose/model/fields.rb', line 289

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.



286
287
288
# File 'lib/nose/model/fields.rb', line 286

def entity
  @entity
end

#relationshipObject (readonly)

Returns the value of attribute relationship.



286
287
288
# File 'lib/nose/model/fields.rb', line 286

def relationship
  @relationship
end

#reverseObject

Returns the value of attribute reverse.



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

def reverse
  @reverse
end

Instance Method Details

#cardinalityInteger

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

Returns:



299
300
301
# File 'lib/nose/model/fields.rb', line 299

def cardinality
  @entity.count || super
end