(glorp) what does #newAttributeNamed:type: do?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

(glorp) what does #newAttributeNamed:type: do?

oystein
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:?
Reply | Threaded
Open this post in threaded view
|

Re: (glorp) what does #newAttributeNamed:type: do?

Alan Knight-2
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.



[hidden email]
June 15, 2011 4:51 AM


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:?


--
View this message in context: http://forum.world.st/glorp-what-does-newAttributeNamed-type-do-tp3598893p3598893.html
Sent from the VisualWorks mailing list archive at Nabble.com.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc