SubSonic Forums
All Your Database Are Belong To Us

Update FK References

Latest post 10-05-2008 9:29 PM by kenexcelon. 3 replies.
  • 10-03-2008 4:03 PM

    Update FK References

    Is there a call within Subsonic that will update FK references to appropriate values if a PK table is updated? 

  • 10-04-2008 3:22 AM In reply to

    Re: Update FK References

    Are you talking about updating the foreign keys in the database or the values in your related objects?

    The database should either update or reject the changes depending on how you have set up the fk.

    I think your objects will need to be re-loaded to reflect any changes the database will have made, I cant remember seeing any code in subsonic that persists the primary key change to affected foreign key values.

    I think the idea of changing the PK would be a bit foreign to the Subsonic convention of using non-contextual PKs, so I cant see it being catered for in the model. But, I have been wrong several dozen times before Embarrassed

     

     

     

  • 10-05-2008 8:29 PM In reply to

    Re: Update FK References

    I am confused, its generally considered extremely bad practice to update the PK.  Even so, cascading that would be very problematic.  I certainly would not expect SubSonic to support that scenario.

    Software Is Like Cathedrals: First we build 'em, then we pray.
  • 10-05-2008 9:29 PM In reply to

    Re: Update FK References

    Sorry if I confused you.  I should have explained the circumstances.  I am not truly updating the PK itself.  Although, I ended up changing the table design.  I'm upgrading a system with a team of a few colleagues.  What would happen, there is a Department table with an identity field.  And also, a unique index for Department Abbreviation.  The other tables hold a FK reference back to the department abbreviation but due to the FK constraint, a department couldn't have it's department abbreviation changed.  Not my design....  I changed the other tables to reference the PK (identity field) directly and went and modified all of the views to grab the information based off of that.  It was just in so many places, I was just hoping there was a way using SubSonic to do it, would have saved me 12 hours of work.  I'm only starting my career, and I knew that was a bad design setup for the database schema.  It was fine from a data integrity standpoint, but not the best way to do it for sure.  Thanks for your replies.  Sometimes the easy solution will not suffice anyway.

     

    Take care. Big Smile

Page 1 of 1 (4 items) | RSS