Hi
Im building a descriptor system with Glorp and the classModelForCLASSNAME. For a DirectMapping i usually use somehting like: aClassModel newAttributeNamed: #anAttribute. Ive noticed that i may also say: aClassModel newAttributeNamed: #anAttribute type: Integer. I assumed that this would specify that anAttribute is an instance variable of type Integer. The corresponding field in the DB table is a float. When loading the object from the DB, the instance variable anAttribute is still loaded as a float. My question is what is the point of #newAttribute:type:? |
Using that API, or anything else that would set the type of the
attribute does what you'd expect, it sets the type of the attribute.
The most significant use of that type is, as you're expecting, doing conversions. When you have a direct mapping to a variable, it will have a converter, and the converter you get is based on the type of the field and the type of the attribute. So in the case you're describing, where you have an Integer type and some kind of numeric field, you'd presumably get a #numberToInteger converter, which would get called via convertedStValueOf:, and end up in convertToInteger:for:. The same sort of techniques let you automatically do things like having a boolean instance variable mapped to a number or string in the database. If I read something which has an integer type, I do see it end up in that converter method, whose code is ^aNumber isNil ifTrue: [aNumber] ifFalse: [aNumber asNumber asInteger]. So yes, I'd expect it to get converted to an integer. If you're not seeing that, then something peculiar is going on.
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |