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 -- 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 [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en. |
It sounds like what you're looking for is DirectToManyMapping.
On Tue, Sep 18, 2012 at 3:35 AM, nickd <[hidden email]> wrote: > 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 > > -- > 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 [hidden email]. > To unsubscribe from this group, send email to > [hidden email]. > For more options, visit this group at > http://groups.google.com/group/glorp-group?hl=en. -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en. |
Rrr®rrÝuoíù¶c0fh¡
---- Envoyé avec BlackBerry® d'Orange ---- -----Original Message----- From: Alan Knight <[hidden email]> Sender: [hidden email] Date: Tue, 18 Sep 2012 22:37:04 To: <[hidden email]> Reply-To: [hidden email] Subject: Re: Best way to map a collection of strings using Glorp It sounds like what you're looking for is DirectToManyMapping. On Tue, Sep 18, 2012 at 3:35 AM, nickd <[hidden email]> wrote: > 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 > > -- > 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 [hidden email]. > To unsubscribe from this group, send email to > [hidden email]. > For more options, visit this group at > http://groups.google.com/group/glorp-group?hl=en. -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en. -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en. |
In reply to this post by Alan Knight-2
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 On Wednesday, 19 September 2012 06:37:05 UTC+1, Alan Knight wrote: 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/-/_o0GR-oIoEgJ. To post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en. |
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. On Wed, Sep 19, 2012 at 1:54 AM, nickd <[hidden email]> wrote: > 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 > > > On Wednesday, 19 September 2012 06:37:05 UTC+1, Alan Knight wrote: >> >> 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/-/_o0GR-oIoEgJ. > > To post to this group, send email to [hidden email]. > To unsubscribe from this group, send email to > [hidden email]. > For more options, visit this group at > http://groups.google.com/group/glorp-group?hl=en. -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To post to this group, send email to [hidden email]. To unsubscribe from this group, send email to [hidden email]. For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en. |
Free forum by Nabble | Edit this page |