How to map table with two references #762
Replies: 4 comments 1 reply
-
| Postgres table structure wise, both columns  My guess is something about the  It is possible for a  HasMany(x => x.Vehicles)
    .Inverse()
    .Cascade.Refresh()
    .Table(JoinNames([TableNames.efcore, TableNames.wbe, nameof(Vehicle).ToLower()])); | 
Beta Was this translation helpful? Give feedback.
-
| Well here's a hair brained crazy idea... And I've got something similar already in  | 
Beta Was this translation helpful? Give feedback.
-
| I am starting to wonder if perhaps in the case of an optional  | 
Beta Was this translation helpful? Give feedback.
-
| Got some updates here, and I think perhaps it may be rooted somewhere in our API reconciliation algorithms, half a dozen or so, several of which potentially impact squads, players (three or four alone, for different things), vehicles, and so forth. Reconciling from upstream API response is usually a three step process. Update the existing instances, add new instances, and remove non-existing instances, after basically taking some set intersections between respective dictionary ids. So bare minimum the API recon needs to also include the zero instances, as this is internally manifested for consistency sake. ... Again back to the indication of, "1-many having some precedence issues" ... Or at least what seems to be precedence issues. Initiially I thought perhaps I might need to introduce some joining tables in order to allow root entity instances to be able to save or update persistently, before thinking about their respective joining relationships. In most cases, I have a root entity T which may have zero or more of another entity U. So to this point I have a U.T property when I need to call back to the 'owner instance'. Does it make sense? High level, 10K meter view, I have these, arrows indicating generally having many of a thing. High level, multiple squads can appear on a server, as can multiple players. Generally, I have the source table mapped, having many of a constituent collection. Then I also have usually a reference mapped, in most cases to at least server, in the case of players, also a squad reference; and in the case of vehicles, also an owner (player) reference. I am getting exceptions kicked back to me indicating some issues with transient instances during save or update. And inspecting the references, relationships, I'm not sure how better to negotiate the mapping. I start with a default 'null instance' basically 'zero' for constitient ids which we use to identity 'ghost' or a unaligned squad and/or player instance. All unaligned players are members of the zero squad; and all wild (not owned) vehicles 'belong' to the zero player. We do this for referential consistency throughout, it just makes sense to do that. I think we have sort of a chicken before the egg issue going on somehow, not sure how better to train the fluent mappings to prefer one entity persistence before the next. And indeed there are 10, 4, 134 transient, players, squads, vehicles, respectively. This is all we get from the exception message, nothing as far as I can tell in the database logs. So best guess either player and/or squad in question, or the reference therein, is somehow transient, player to squad, before the squad having been persistent. And indeed there are some "unaligned" or "individual" players, which squad is not among the squads to be saved or updated. Maybe there is also a better way to introduce joining tables such that the source entities are allowed to persist unimpeded, apart from the 'root parent-child' reference, if you will; by associated references, then to persist those joins. I don't think there are any properties associated with the joins, per se, so perhaps the 'vanilla' (fluent) nhibernate joining protocols would be adequate in this case. I also need to double check, there are half a dozen or so API conversations going on in which I may also be inadvertently dropping "non-existing" ids, either squad, or player, in which for instance id is 'zero'. In other words thos need to also respect the zero instance, allowing that to persist as well. Is probably the simplest thing to verify what is going on. Any ideas? Would be great if there were a discord, or at least more engagement here, or via github discussions, perhaps. Thank you... | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a table
Vehiclewith effectively two references. One toMotorVehicleDivisionwhich must exist.Another to
Ownerwhich may or may not exist. In context vehicle may be found in the wild as it were, no owner, so may benull.MotorVehicleDivisionside of things, the mapping is,AllDeleteOrphansis correct here, I believe, if for any reason anMVDinstance goes away, should pull all theVehicleobjects along with it:Ownerside is a bit trickier, ifPlayergoes away for any reason should leaveVehicleintact, so we simplyRefresh, I think,Inverseas well, of course.Having some difficulty saving, somewhere along the way the relationships are being dropped and the transaction is rolling back.
Anyone better versed in this sort of mapping, perhaps, any insights?
Initially I thought perhaps a many-to-many joining table, however, this is really overkill,
Vehiclecannot have multiple owners, so the next best shot at it, is this, I think.Internally we respond with appropriate collections, observability, and so forth, to ensure that the properties are properly affected prior to
SaveOrUpdate.I am getting an error:
NHibernate.ObjectDeletedException: 'deleted object would be re-saved by cascade (remove deleted object from associations)[WhalleyBotEnhanced.Player#xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx]'.Saving is properly contained in a
trycatchand transacted so I get commits and rollbacks "for free" as part of that callback. I've verified that much of the repository pattern works, just having a bit of difficulty persuading the one and a half parents (MVD the true parent, Owner being 'parent' but may benull).Any ideas how to better approach this one?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions