diff --git a/src/Glorp-Integration-Tests/GlorpReadingPersonWithEmailAddressesTest.class.st b/src/Glorp-Integration-Tests/GlorpReadingPersonWithEmailAddressesTest.class.st index 4a58c40c..081b8a1c 100644 --- a/src/Glorp-Integration-Tests/GlorpReadingPersonWithEmailAddressesTest.class.st +++ b/src/Glorp-Integration-Tests/GlorpReadingPersonWithEmailAddressesTest.class.st @@ -126,18 +126,17 @@ GlorpReadingPersonWithEmailAddressesTest >> testReadMultipleObjectsOneToMany [ { #category : #tests } GlorpReadingPersonWithEmailAddressesTest >> testReadPersonWithEmailAddresses [ + | query result emailAddresses | query := Query - readOneOf:GlorpPerson - where: [:person | person id = 3]. + readOneOf: GlorpPerson + where: [ :person | person id = 3 ]. result := query executeIn: session. emailAddresses := result emailAddresses getValue. self assert: emailAddresses size = 2. - self - assert: - (emailAddresses first id = id1 or: [emailAddresses last id = id1]). - self - assert: - (emailAddresses first id = id2 or: [emailAddresses last id = id2]). - self assert: emailAddresses first id ~= emailAddresses last id. + self assert: + (emailAddresses first id = id1 or: [ emailAddresses last id = id1 ]). + self assert: + (emailAddresses first id = id2 or: [ emailAddresses last id = id2 ]). + self assert: emailAddresses first id ~= emailAddresses last id ] diff --git a/src/Glorp-Integration-Tests/GlorpReadingPersonWithoutEmailAddressesTest.class.st b/src/Glorp-Integration-Tests/GlorpReadingPersonWithoutEmailAddressesTest.class.st new file mode 100644 index 00000000..a74f42e5 --- /dev/null +++ b/src/Glorp-Integration-Tests/GlorpReadingPersonWithoutEmailAddressesTest.class.st @@ -0,0 +1,49 @@ +Class { + #name : #GlorpReadingPersonWithoutEmailAddressesTest, + #superclass : #GlorpTestCase, + #instVars : [ + 'session', + 'personRow' + ], + #category : #'Glorp-Integration-Tests-Database' +} + +{ #category : #resources } +GlorpReadingPersonWithoutEmailAddressesTest class >> resources [ + ^Array with: GlorpSessionResource. +] + +{ #category : #running } +GlorpReadingPersonWithoutEmailAddressesTest >> setUp [ + + super setUp. + session := GlorpSessionResource current newSession. + session beginTransaction. + personRow := session system examplePersonRow2. + session writeRow: personRow. + +] + +{ #category : #running } +GlorpReadingPersonWithoutEmailAddressesTest >> tearDown [ + + session rollbackTransaction. + session reset. + session := nil. + super tearDown +] + +{ #category : #tests } +GlorpReadingPersonWithoutEmailAddressesTest >> testReadMultipleObjectsOneToMany [ + + | query result person addresses | + + query := Query read: GlorpPerson where: [ :eachPerson | eachPerson id = 4 ]. + query alsoFetch: [ :each | each emailAddresses asOuterJoin ]. + result := query executeIn: session. + self assert: result size equals: 1. + person := result first. + addresses := person emailAddresses. + self deny: addresses isGlorpProxy "testing PR https://github.com/pharo-rdbms/glorp/pull/115". + self assert: addresses size equals: 0 +] diff --git a/src/Glorp/GlorpAttributeModel.class.st b/src/Glorp/GlorpAttributeModel.class.st index 6586700a..c4a97fea 100644 --- a/src/Glorp/GlorpAttributeModel.class.st +++ b/src/Glorp/GlorpAttributeModel.class.st @@ -280,29 +280,21 @@ GlorpAttributeModel >> keyType: aClass [ ] { #category : #knitting } -GlorpAttributeModel >> knit: ourObject to: anotherObject [ +GlorpAttributeModel >> knit: ourObject to: anotherObject [ "Set up the relationship from our object to another one, indicated by our mapping." - self isCollectionAttribute - ifTrue: - [| collection | + self isCollectionAttribute + ifTrue: [ + | collection | collection := self getValueFrom: ourObject. - (collection isGlorpProxy and: [collection isInstantiated not]) - ifTrue: - [collection := self newCollection. - self setValueIn: ourObject to: collection. - self - add: anotherObject - to: collection - in: ourObject. - ^self]. - (collection includes: anotherObject) - ifFalse: - [self - add: anotherObject - to: collection - in: ourObject]] - ifFalse: [self setValueIn: ourObject to: anotherObject] + (collection isGlorpProxy and: [ collection isInstantiated not ]) + ifTrue: [ + collection := self newCollection. + self setValueIn: ourObject to: collection ]. + anotherObject ifNotNil: [ + (collection includes: anotherObject) ifFalse: [ + self add: anotherObject to: collection in: ourObject ] ] ] + ifFalse: [ self setValueIn: ourObject to: anotherObject ] ] { #category : #mapping } diff --git a/src/Glorp/GlorpCursoredStream.class.st b/src/Glorp/GlorpCursoredStream.class.st index 27e16f62..68662ec2 100644 --- a/src/Glorp/GlorpCursoredStream.class.st +++ b/src/Glorp/GlorpCursoredStream.class.st @@ -28,7 +28,7 @@ Class { 'rawPeekBuffer', 'statement' ], - #category : 'Glorp-Queries' + #category : #'Glorp-Queries' } { #category : #'instance creation' } @@ -79,24 +79,24 @@ GlorpCursoredStream >> atEnd [ { #category : #'building objects' } GlorpCursoredStream >> buildObjectsForRow: aRow [ - self query isNil ifTrue: [^aRow]. - builders - do: - [:each | each findInstanceForRow: aRow proxyType: self query proxyType]. - builders do: [:each | each buildObjectFrom: aRow]. - builders - do: - [:each | - each - sendPostFetchValidateIn: self session - OnFailureDo: [each instance: nil]]. - builders - do: [:each | each instance == nil ifFalse: [each knitResultIn: self]]. - builders do: [:each | self session sendPostFetchEventTo: each instance]. - ^self buildersThatReturnResults size = 1 - ifTrue: [self buildersThatReturnResults first returnValueIn: self] - ifFalse: - [self buildersThatReturnResults collect: [:each | each returnValueIn: self]] + + self query isNil ifTrue: [ ^ aRow ]. + builders do: [ :each | + each findInstanceForRow: aRow proxyType: self query proxyType ]. + builders do: [ :each | each buildObjectFrom: aRow ]. + builders do: [ :each | + each + sendPostFetchValidateIn: self session + OnFailureDo: [ each instance: nil ] ]. + builders do: [ :each | each knitResultIn: self ]. + builders do: [ :each | + self session sendPostFetchEventTo: each instance ]. + ^ self buildersThatReturnResults size = 1 + ifTrue: [ + self buildersThatReturnResults first returnValueIn: self ] + ifFalse: [ + self buildersThatReturnResults collect: [ :each | + each returnValueIn: self ] ] ] { #category : #'building objects' }