Best way to map a collection of strings using Glorp

27 views
Skip to first unread message

nickd

unread,
Sep 18, 2012, 6:35:29 AM9/18/12
to glorp...@googlegroups.com
Hello,
  Quick question on how best to code the following scenario in Glorp.

Say you have a class of Application , representing a software product. One of its attributes is a collection of strings containing versions, such as
1.0,  2.0. , 3.3. 4.0. 4.5 etc
(Although these all happen to be numbers, they are stored as strings).

How do you map this collection of strings to the underlying table?

What I've done so far instead is create a seperate class called ApplicationVersion, defined a table specifically for that class, and made the versions attribute a collection of ApplicationVersions.
This seems like overkill and is causing problems because every time you add a version you then add an instance of ApplicationVersion.

The underlying link table should presumably be like this, regardless of how the mapping is coded :

application   version
---------------    ----------
productA       1.0
productA       2.0
productB       1.5
etc

Is it possible for glorp to use a table like that, without having to define a seperate class for model the relationship?

I'm surprised to be unable to find examples as this doesn't seem a completely unusual scenario.

Is there an example in the glorp test suite somewhere?
Thanks a lot,
Nick Davis

Alan Knight

unread,
Sep 19, 2012, 1:37:04 AM9/19/12
to glorp...@googlegroups.com
It sounds like what you're looking for is DirectToManyMapping.
> --
> You received this message because you are subscribed to the Google Groups
> "glorp-group" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/glorp-group/-/j23-Y8cD7sEJ.
> To post to this group, send email to glorp...@googlegroups.com.
> To unsubscribe from this group, send email to
> glorp-group...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/glorp-group?hl=en.

maarten...@stakepoint.com

unread,
Sep 19, 2012, 2:43:36 AM9/19/12
to glorp...@googlegroups.com
Rrr®rrÝuoíù¶c0fh¡
---- Envoyé avec BlackBerry® d'Orange ----

nickd

unread,
Sep 19, 2012, 4:54:09 AM9/19/12
to glorp...@googlegroups.com
Hello Alan,
  Thanks for the reply. DirectToManyMapping looks just right thanks. However, due to the lack of many examples so far and that the class comment says "This should be regarded as something of a prototype. It seems to work, at least for basic operations, but it may well have problems." I think for now I will stick a load of comma separated values in a big varchar (I know, not pretty).
  BTW am loving using glorp. Its very elegant. :)
Regards,
Nick

Alan Knight

unread,
Sep 19, 2012, 12:27:51 PM9/19/12
to glorp...@googlegroups.com
Yes, putting them in a varchar will work. You can map that with an
AdHocMapping a little better, though those are complicated to write.
Basically, that's saying Glorp doesn't know how to map this, but you
can have access to the internals to tell it how to read and write. You
can also map something like that as a dictionary using the strings as
either the keys or the values. If order is important, you could use
the index in the collection as either the key or the value. But that's
also kind of messy.

And thanks, I'm glad you're enjoying it.
> --
> You received this message because you are subscribed to the Google Groups
> "glorp-group" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/glorp-group/-/_o0GR-oIoEgJ.
Reply all
Reply to author
Forward
0 new messages