I am using ActiveRecord from Love it.

I have inherited a database, so I can’t change the structure. I understand that what I am saying is bad database design, but it is what it is.

I have tableA and tableB.

TableA is a list of pieces of equipment. TableB is a list of Equipment Types, varchar(5).
Normally database design would dictate that you would use the primary key (auto incrementing, integer) as the value you put in TableA, however the person that originally designed this put the actual Equipment Type in TableA.

My problem is that if someone changes the equipment type in TableB, I need to change all the records in TableA for that old equipment type to the new equipment type.

I don’t know if it’s best to put the code in the validate area at the end after all validation is done, but I would have both the old and new value,
or put in the BeforeUpdate, or AfterUpdate or BeforeSave, or AfterSave Events for the class. I’m not sure how to reference the old and new values so I can do the update statement on TableA.

Any help would be appreciated, and documented here in case anyone else has the same question at a future date.


Yeah, that’s a bad design, but these are the things we get with Other Peoples Code (OPC) projects. Database design is often done by people that have no business designing databases.

What I would do is in the AfterUpdate event of TableB execute a SQL Query that changes TableA to the correct values. You could probably add a property to your TableB class using the BeforeSave event to save the old value and then use that value in the SQL Query in the AfterSave event.

Thanks, I will try that later today and let everyone know how it goes.

Just to let you know, there is a dictionary in the base class that keeps a copy of all the original values, but there’s no easy way to get to it without adding some methods. Probably easier to use the Before and After save events.

Use a trigger