EmbeddedValueOneToOneMapping that returns nil when all embedded columns are nil

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

EmbeddedValueOneToOneMapping that returns nil when all embedded columns are nil

jtuchel
HI again,

I've been using Glorp quiet happily for a few months, you can see that in the frequency of posts to this forum ;-)

But now I have a question.

I am using an EmbeddedValueOneToOneMapping to map two date columns to a TimeSpan- or Period-kind of Class (Zeitraum in German), which has a startDate and an endDate.
Here is an exaple mapping:

        (aDescriptor newMapping: EmbeddedValueOneToOneMapping)
        attributeName: #membershipPeriod;
        fieldTranslation: (
            (Join new)
                addSource: (table fieldNamed: 'membership_start')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'startDate');
                addSource: (table fieldNamed: 'membership_end')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'endDate');
                yourself).



This works great - until today. It seems I always only hat timespans that at least have a startDate. But now I need to use it for a table/class in which both start and end date can be NULL. In that case, I'd like to habe a #membershipPeriod of nil rather than a Period with both dates being nil.

I am sure there is some way to tell this embedded mapping to check such situations. I tried beOuterJoin, but that didn't help.

I hope I've explained my use case well and somebody here can help me

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/be037b6a-dde2-44a5-ae5e-97acec3116bc%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: EmbeddedValueOneToOneMapping that returns nil when all embedded columns are nil

Annick-2
Hi,
Have a look at the following (old) documentation for embedded values.
Annick

Le jeudi 23 janvier 2020 17:57:13 UTC+1, jtuchel a écrit :
HI again,

I've been using Glorp quiet happily for a few months, you can see that in the frequency of posts to this forum ;-)

But now I have a question.

I am using an EmbeddedValueOneToOneMapping to map two date columns to a TimeSpan- or Period-kind of Class (Zeitraum in German), which has a startDate and an endDate.
Here is an exaple mapping:

        (aDescriptor newMapping: EmbeddedValueOneToOneMapping)
        attributeName: #membershipPeriod;
        fieldTranslation: (
            (Join new)
                addSource: (table fieldNamed: 'membership_start')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'startDate');
                addSource: (table fieldNamed: 'membership_end')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'endDate');
                yourself).



This works great - until today. It seems I always only hat timespans that at least have a startDate. But now I need to use it for a table/class in which both start and end date can be NULL. In that case, I'd like to habe a #membershipPeriod of nil rather than a Period with both dates being nil.

I am sure there is some way to tell this embedded mapping to check such situations. I tried beOuterJoin, but that didn't help.

I hope I've explained my use case well and somebody here can help me

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/5f8b5e0b-b276-4aa0-94d9-9fdc7a8124d4%40googlegroups.com.

GlorpTutorial.pdf (288K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: EmbeddedValueOneToOneMapping that returns nil when all embedded columns are nil

jtuchel
Hi Annick,

thanks for the document.

T've been using EmbeddedValueOneToOneMapping for a while now. The problem is that tehy always return an instance of the mapped class with nil variables in it instead of returning nil.
In the example from the document, you' always get an instance fo class Name which holds nil in its #first and #last instance variables. I'd like to get a nil instead of a Name object when both mapped attributes are nil...


Joachim



Am Donnerstag, 14. Mai 2020 18:17:21 UTC+2 schrieb Annick:
Hi,
Have a look at the following (old) documentation for embedded values.
Annick

Le jeudi 23 janvier 2020 17:57:13 UTC+1, jtuchel a écrit :
HI again,

I've been using Glorp quiet happily for a few months, you can see that in the frequency of posts to this forum ;-)

But now I have a question.

I am using an EmbeddedValueOneToOneMapping to map two date columns to a TimeSpan- or Period-kind of Class (Zeitraum in German), which has a startDate and an endDate.
Here is an exaple mapping:

        (aDescriptor newMapping: EmbeddedValueOneToOneMapping)
        attributeName: #membershipPeriod;
        fieldTranslation: (
            (Join new)
                addSource: (table fieldNamed: 'membership_start')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'startDate');
                addSource: (table fieldNamed: 'membership_end')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'endDate');
                yourself).



This works great - until today. It seems I always only hat timespans that at least have a startDate. But now I need to use it for a table/class in which both start and end date can be NULL. In that case, I'd like to habe a #membershipPeriod of nil rather than a Period with both dates being nil.

I am sure there is some way to tell this embedded mapping to check such situations. I tried beOuterJoin, but that didn't help.

I hope I've explained my use case well and somebody here can help me

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/c917d81c-5d3a-465c-ac72-668b350ad4b0%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: EmbeddedValueOneToOneMapping that returns nil when all embedded columns are nil

Annick-2
Hi Joachim,

I don't have any issues. When you modify the value, do you register both the embedding and the embedded object ?


Le jeudi 14 mai 2020 19:31:27 UTC+2, jtuchel a écrit :
Hi Annick,

thanks for the document.

T've been using EmbeddedValueOneToOneMapping for a while now. The problem is that tehy always return an instance of the mapped class with nil variables in it instead of returning nil.
In the example from the document, you' always get an instance fo class Name which holds nil in its #first and #last instance variables. I'd like to get a nil instead of a Name object when both mapped attributes are nil...


Joachim



Am Donnerstag, 14. Mai 2020 18:17:21 UTC+2 schrieb Annick:
Hi,
Have a look at the following (old) documentation for embedded values.
Annick

Le jeudi 23 janvier 2020 17:57:13 UTC+1, jtuchel a écrit :
HI again,

I've been using Glorp quiet happily for a few months, you can see that in the frequency of posts to this forum ;-)

But now I have a question.

I am using an EmbeddedValueOneToOneMapping to map two date columns to a TimeSpan- or Period-kind of Class (Zeitraum in German), which has a startDate and an endDate.
Here is an exaple mapping:

        (aDescriptor newMapping: EmbeddedValueOneToOneMapping)
        attributeName: #membershipPeriod;
        fieldTranslation: (
            (Join new)
                addSource: (table fieldNamed: 'membership_start')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'startDate');
                addSource: (table fieldNamed: 'membership_end')
                    target: ((self tableNamed: 'ZEITRAUM_EMBEDDED') fieldNamed: 'endDate');
                yourself).



This works great - until today. It seems I always only hat timespans that at least have a startDate. But now I need to use it for a table/class in which both start and end date can be NULL. In that case, I'd like to habe a #membershipPeriod of nil rather than a Period with both dates being nil.

I am sure there is some way to tell this embedded mapping to check such situations. I tried beOuterJoin, but that didn't help.

I hope I've explained my use case well and somebody here can help me

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/082747f0-8cd3-45c1-8da6-4e02ef0f7878%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: EmbeddedValueOneToOneMapping that returns nil when all embedded columns are nil

jtuchel
Hi Annick,

I don't have any issues writing objects, I usually only register the embedding object and that saves both the embedding and the embedded object just fine.

The problem arises when reading objects back from the database and all columns that are mapped to an embedded object are NULL. Then I don't get a nil, but what I get is an instance of the class of the embedded object, all variables containing nil. I'd like to retrieve the whole embedded object as nil, however.

So in my example I can easily save objects containing a membership period as nil, which will result in NULL in both columns:  startDate  and endDate.
But when I read the embedding object back into Glorp, the membership period will always be a membershipPeriodObject with a startDate of nil and an endDate of Nil. What I'd be able to get bakc from the database is nil instead of a MembershipPeriod Instance.


Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/aec5519c-e14e-41ea-bc0b-3a1def9332be%40googlegroups.com.