Class: Lafcadio::LinkField
- Inherits:
-
ObjectField
- Object
- ObjectField
- Lafcadio::LinkField
- Defined in:
- lib/lafcadio/objectField/LinkField.rb
Overview
A LinkField is used to link from one domain class to another.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#deleteCascade ⇒ Object
Returns the value of attribute deleteCascade.
-
#linkedType ⇒ Object
readonly
Returns the value of attribute linkedType.
-
#listener ⇒ Object
Returns the value of attribute listener.
-
#newDuringEdit ⇒ Object
Returns the value of attribute newDuringEdit.
-
#objectStore ⇒ Object
Returns the value of attribute objectStore.
-
#sortField ⇒ Object
Returns the value of attribute sortField.
Attributes inherited from ObjectField
#dbFieldName, #default, #defaultFieldName, #hideDisplay, #hideLabel, #name, #notNull, #notUniqueMsg, #objectType, #unique, #writeOnce
Class Method Summary collapse
-
.instantiateWithParameters(domainClass, parameters) ⇒ Object
:nodoc:.
-
.instantiationParameters(fieldElt) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(objectType, linkedType, name = nil, englishName = nil, deleteCascade = false) ⇒ LinkField
constructor
- objectType
-
The domain class that this field belongs to.
-
#valueForSQL(value) ⇒ Object
:nodoc:.
-
#valueFromSQL(string) ⇒ Object
:nodoc:.
-
#verify(value, pkId) ⇒ Object
:nodoc:.
Methods inherited from ObjectField
#<=>, #bind_write?, #dbWillAutomaticallyWrite, #db_table_and_field_name, #englishName, #firstTime, instantiateFromXml, #nameForSQL, #nullErrorMsg, #prevValue, #processBeforeVerify, valueType, #verifyUniqueness
Constructor Details
#initialize(objectType, linkedType, name = nil, englishName = nil, deleteCascade = false) ⇒ LinkField
- objectType
-
The domain class that this field belongs to.
- linkedType
-
The domain class that this field points to.
- name
-
The name of this field.
- englishName
-
The English name of this field. (Deprecated)
- deleteCascade
-
If this is true, deleting the domain object that is linked to will cause this domain object to be deleted as well.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 37 def initialize( objectType, linkedType, name = nil, englishName = nil, deleteCascade = false ) unless name linkedType.name =~ /::/ name = $' || linkedType.name name = name.decapitalize end super(objectType, name, englishName) ( @linkedType, @deleteCascade ) = linkedType, deleteCascade @listener = nil @newDuringEdit = true end |
Instance Attribute Details
#deleteCascade ⇒ Object
Returns the value of attribute deleteCascade.
28 29 30 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 28 def deleteCascade @deleteCascade end |
#linkedType ⇒ Object (readonly)
Returns the value of attribute linkedType.
27 28 29 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 27 def linkedType @linkedType end |
#listener ⇒ Object
Returns the value of attribute listener.
28 29 30 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 28 def listener @listener end |
#newDuringEdit ⇒ Object
Returns the value of attribute newDuringEdit.
28 29 30 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 28 def newDuringEdit @newDuringEdit end |
#objectStore ⇒ Object
Returns the value of attribute objectStore.
28 29 30 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 28 def objectStore @objectStore end |
#sortField ⇒ Object
Returns the value of attribute sortField.
28 29 30 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 28 def sortField @sortField end |
Class Method Details
.instantiateWithParameters(domainClass, parameters) ⇒ Object
:nodoc:
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 16 def LinkField.instantiateWithParameters( domainClass, parameters ) #:nodoc: instance = self.new( domainClass, parameters['linkedType'], parameters['name'], parameters['englishName'], parameters['deleteCascade'] ) if parameters['dbFieldName'] instance.dbFieldName = parameters['dbFieldName'] end instance end |
.instantiationParameters(fieldElt) ⇒ Object
:nodoc:
7 8 9 10 11 12 13 14 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 7 def LinkField.instantiationParameters( fieldElt ) #:nodoc: parameters = super( fieldElt ) linkedTypeStr = fieldElt.attributes['linkedType'] linkedType = DomainObject.getObjectTypeFromString( linkedTypeStr ) parameters['linkedType'] = linkedType parameters['deleteCascade'] = fieldElt.attributes['deleteCascade'] == 'y' parameters end |
Instance Method Details
#valueForSQL(value) ⇒ Object
:nodoc:
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 50 def valueForSQL(value) #:nodoc: require 'lafcadio/objectStore/DomainObjectInitError' if !value "null" elsif value.pkId value.pkId else raise( DomainObjectInitError, "Can't commit #{name} without pkId", caller ) end end |
#valueFromSQL(string) ⇒ Object
:nodoc:
62 63 64 65 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 62 def valueFromSQL(string) #:nodoc: require 'lafcadio/objectStore/DomainObjectProxy' string != nil ? DomainObjectProxy.new(@linkedType, string.to_i) : nil end |
#verify(value, pkId) ⇒ Object
:nodoc:
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/lafcadio/objectField/LinkField.rb', line 67 def verify(value, pkId) #:nodoc: super if @linkedType != @objectType && pkId subsetLinkField = nil @linkedType.classFields.each { |field| if field.class == SubsetLinkField && field.subsetField == @name subsetLinkField = field end } if subsetLinkField begin prevObj = ObjectStore.getObjectStore.get(objectType, pkId) prevObjLinkedTo = prevObj.send(name) possiblyMyObj = prevObjLinkedTo.send(subsetLinkField.name) if possiblyMyObj && possiblyMyObj.pkId == pkId cantChangeMsg = "You can't change that." raise FieldValueError, cantChangeMsg, caller end rescue DomainObjectNotFoundError # no previous value, so nothing to check for end end end end |