Can't nil out nullable 1 to 1 field

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

Can't nil out nullable 1 to 1 field

David Buck-3
I have an object called a Ticket which has a one-to-one nullable relationship
to a Code_Release.  When I try to set the field in the ticket to nil, it
doesn't make that change in the database.  The funny think is that it's
happy to increment the version number but doesn't nil codeRelease.  Any
ideas?  I'm using the Glorp packaged with VisualWorks 7.10.1 with an Oracle
database.

Details:

Code to nil the code release:

	MyGlorpSession inUnitOfWorkDo: [:session |
		selectedCodeRelease tickets do: [:ticket |
			session register: ticket.
			ticket version: ticket version + 1.
			ticket codeRelease: nil]].


Ticket class model:
classModelForTicket: aClassModel
	aClassModel
		newAttributeNamed: #id;
		newAttributeNamed: #version;
		newAttributeNamed: #codeRelease type: TicketCodeRelease

Ticket mappings:
descriptorForTicket: aDescriptor
	| table |
	table := self tableNamed: 'TICKETS'.
	aDescriptor table: table.
	(aDescriptor newMapping: Glorp.DirectMapping) from: #id to: (table
fieldNamed: 'id_pk').
	(aDescriptor newMapping: Glorp.DirectMapping) from: #version to: (table
fieldNamed: 'version_lk').
	(aDescriptor newMapping: Glorp.OneToOneMapping)
		attributeName: #codeRelease;
		mappingCriteria: (
			Glorp.Join
				from: (table fieldNamed: 'code_release_fk')
				to: ((self tableNamed: 'CODE_RELEASES') fieldNamed: 'id_pk')).

Ticket table:
tableForTICKETS: aTable

	| codeReleaseField |
	(aTable createFieldNamed: 'id_pk' type: platform sequence) bePrimaryKey.
	(aTable createFieldNamed: 'version_lk' type: platform integer) beLockKey.
	(codeReleaseField := aTable createFieldNamed: 'code_release_fk' type:
platform integer) beNullable: true.
	aTable
		addForeignKeyFrom: codeReleaseField
		to: ((self tableNamed: 'CODE_RELEASES') fieldNamed: 'id_pk').

--
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 post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't nil out nullable 1 to 1 field

Alan Knight
That does seem odd. It's possible to set debugWrite on a making, which might tell you something, although it does plunge you deep into glorp internals.

It probably doesn't help, assuming the mailing is otherwise working, but you should be able to leave off the mapping criteria. There's enough information in the schema and the variable type for it to figure that all out.

On Fri, Mar 10, 2017, 22:39 David Buck <[hidden email]> wrote:
I have an object called a Ticket which has a one-to-one nullable relationship
to a Code_Release.  When I try to set the field in the ticket to nil, it
doesn't make that change in the database.  The funny think is that it's
happy to increment the version number but doesn't nil codeRelease.  Any
ideas?  I'm using the Glorp packaged with VisualWorks 7.10.1 with an Oracle
database.

Details:

Code to nil the code release:

	MyGlorpSession inUnitOfWorkDo: [:session |
		selectedCodeRelease tickets do: [:ticket |
			session register: ticket.
			ticket version: ticket version + 1.
			ticket codeRelease: nil]].


Ticket class model:
classModelForTicket: aClassModel
	aClassModel
		newAttributeNamed: #id;
		newAttributeNamed: #version;
		newAttributeNamed: #codeRelease type: TicketCodeRelease

Ticket mappings:
descriptorForTicket: aDescriptor
	| table |
	table := self tableNamed: 'TICKETS'.
	aDescriptor table: table.
	(aDescriptor newMapping: Glorp.DirectMapping) from: #id to: (table
fieldNamed: 'id_pk').
	(aDescriptor newMapping: Glorp.DirectMapping) from: #version to: (table
fieldNamed: 'version_lk').
	(aDescriptor newMapping: Glorp.OneToOneMapping)
		attributeName: #codeRelease;
		mappingCriteria: (
			Glorp.Join
				from: (table fieldNamed: 'code_release_fk')
				to: ((self tableNamed: 'CODE_RELEASES') fieldNamed: 'id_pk')).

Ticket table:
tableForTICKETS: aTable

	| codeReleaseField |
	(aTable createFieldNamed: 'id_pk' type: platform sequence) bePrimaryKey.
	(aTable createFieldNamed: 'version_lk' type: platform integer) beLockKey.
	(codeReleaseField := aTable createFieldNamed: 'code_release_fk' type:
platform integer) beNullable: true.
	aTable
		addForeignKeyFrom: codeReleaseField
		to: ((self tableNamed: 'CODE_RELEASES') fieldNamed: 'id_pk').

--
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 post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.

--
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 post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Loading...