This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi! In our database we have two tables (A,B) which are connected using a connection table (A_B) (defined with a ThroughAssociation in the domain model). Each combination of id's from the two tables A and B has to be unique in the connection table. Now, if i clear the ThroughAssociation list in A (or B), and then insert an item that was previously contained in the list before it was cleared, I get a database constraint error when I save, since LightSpeed inserts the new items before it deletes the cleared items. Is this a LightSpeed bug, or can we force the delete to be done before the insert? Attached is a test-case. It uses MySql as databaseprovider, I hope that is OK. Best regards Björn Andersson Admeta AB |
|
|
You cannot force LightSpeed to do the delete before the insert. LightSpeed always performs inserts first, then updates, then deletes. A possible workaround, however, is to perform a SaveChanges() after clearing the ThroughAssociation. This will flush the deletes. You can then set up the new associations and do another SaveChanges() which will perform the inserts. In order to avoid other users seeing the temporarily empty through association you would want to perform both operations within the same transaction. |
|
|
I'll butt in again since Björn and I discussed this issue today. [quote user="ivan"] A possible workaround, however, is to perform a SaveChanges() after clearing the ThroughAssociation. This will flush the deletes. You can then set up the new associations and do another SaveChanges() which will perform the inserts. [/quote] One interesting approach is what the LLBLGen Pro O/R mapper seem to allow. Look at the "Specifying the order in which the actions are executed" in the following page: http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/SelfServicing/gencode_unitofwork.htm. Would this be somthing that Lightspeed might be able to support in the future? |
|
|
I agree that the proffered workaround is not ideal -- to be fair I did describe it as a "workaround" rather than a "solution" *grin*. I don't see any fundamental issue with allowing application code to override the default order of actions, though it depends on how fine-grained this needs to be. I think specifying "do deletes before inserts" would be reasonably easy. Specifying "do these deletes first, then these inserts, then the remaining deletes" would be a lot harder. It sounds like the first would meet your immediate need though and the second is an edge case which we could look at if it ever came up. I've logged a feature request to do the first option and we'll see if we can fit that in soonish. |
|
|
[quote user="ivan"] I agree that the proffered workaround is not ideal -- to be fair I did describe it as a "workaround" rather than a "solution" *grin*. [/quote] Yes. Sorry. My bad typing. [quote user="ivan"] I've logged a feature request to do the first option and we'll see if we can fit that in soonish. [/quote] Ok, great! Thanks. Of course, we are interested to know whenish |
|
|
We don't currently provide release notes alongside nightly builds, though this is something on our wish list too! We try to post in the relevant forum thread when a nightly includes a feature or bug fix that has come in through the forum -- e.g if/when we implement order control I will post in this thread. |
|