Troubleshooting‎ > ‎

AutoBind and Statement Inheritance

posted Sep 19, 2016, 7:34 PM by Eric Patrick   [ updated Sep 20, 2016, 7:01 AM by Philip Raath ]
The ADR system encountered an unusual use case where Organization/AutoBind did not work as expected. The root cause is that statements inherit the parameters of statements defined in their base class. In this instance, Organization inherits from Contact, and both had an AutoBind statement defined:
  • Organization/AutoBind was defined as SELECT OrganizationID, Organization FROM Organization WHERE Organization = @Organization
    • parameters = Organization
  • Contact/AutoBind was defined as SELECT ... FROM Contact WHERE ObjectID = @ObjectID AND Object = @Object AND Sequence = @Sequence
    • parameters = Object, ObjectID, Sequence
The unexpected behavior was introduced as follows:
  • When the Organization/AutoBind statement was wired, it inherited Contact/AutoBind properties, including the Object, ObjectID and Sequence parameters, and then added it's own parameter (Organization). At this point, Organization/AutoBind included the following parameters: Object, ObjectID, Sequence, and Organization
  • Organization/Save?Organization=Freddie Mac was called
  • When Organization/SetProperties was called, each AutoBind statement was compared to the parameters passed to SetProperties, and if all matching parameters were present, AutoBind is executed
    • In this case the only parameter passed was Organization
    • Since Object, ObjectID and Sequence were not present, AutoBind was not executed
  • Thus, an attempt to save a new Freddie Mac Organization was attempted
The fix for this scenario is to create an alternative AutoBind statement, such as Organization/AutoBindByOrganization with just Organization as a parameter. SetProperties will evaluate all AutoBind* statements, so both of the following calls would trigger an AutoBind:
  • Organization/Save?Organization=Freddie Mac
  • Organization/Save?Organization=Acme Rockets&Object=Organization&ObjectID=1&Sequence=1