Class: NoSE::Fields::ForeignKeyField
- Defined in:
- lib/nose/model/fields.rb
Overview
Field holding a foreign key to another entity
Constant Summary
Constants inherited from Field
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#relationship ⇒ Object
readonly
Returns the value of attribute relationship.
-
#reverse ⇒ Object
Returns the value of attribute reverse.
Attributes inherited from Field
#name, #parent, #primary_key, #size
Instance Method Summary collapse
-
#cardinality ⇒ Fixnum
The number of entities associated with the foreign key, or a manually set cardinality.
-
#initialize(name, entity, **options) ⇒ ForeignKeyField
constructor
A new instance of ForeignKeyField.
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
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, **) @relationship = .delete(:relationship) || :one super(name, **) @primary_key = false @entity = entity end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
275 276 277 |
# File 'lib/nose/model/fields.rb', line 275 def entity @entity end |
#relationship ⇒ Object (readonly)
Returns the value of attribute relationship.
275 276 277 |
# File 'lib/nose/model/fields.rb', line 275 def relationship @relationship end |
#reverse ⇒ Object
Returns the value of attribute reverse.
276 277 278 |
# File 'lib/nose/model/fields.rb', line 276 def reverse @reverse end |
Instance Method Details
#cardinality ⇒ Fixnum
The number of entities associated with the foreign key, or a manually set cardinality
288 289 290 |
# File 'lib/nose/model/fields.rb', line 288 def cardinality @entity.count || super end |