Best place for business logic when one optionally wants to create related records when creating parent records
 
Forums / SmartComponent Library - Developer Forum / Best place for business logic when one optionally wants to create related records when creating parent records

Best place for business logic when one optionally wants to create related records when creating parent records

5 posts, 1 answered
  1. Patrik Wikström
    Patrik Wikström avatar
    70 posts
    Registered:
    15 Oct 2018
    23 Oct 2019
    Link to this post

    Say we have a business entity (BE) with 2 tables eFather and eChild. We have business logic that tells you that in case x and y we want to automatically create a bunch of eChild records when creating new eFather records. Where do we code this logic? We would want to do this in the BE (ReceiveData?) but how to identify that some eFather records has been created? We do know how to do this in the data access (DA) class.

    Second part of question (if DA is the only way), do we want to initiate a second own BE instance (the same BE) in the DA to create the possible eChild records or do we just hit the database tables and make sure that everything that is done in the BE is also done in this case?

    Did I manage to ask this clear enough (probably not)? :)

  2. Mike Fechner
    Mike Fechner avatar
    342 posts
    Registered:
    14 Sep 2016
    23 Oct 2019 in reply to Patrik Wikström
    Link to this post

    When you create the eChild records, they should be stored along the eFather record in the database? 

    In that case ReceiveData is certainly the wrong place - it's just to manipulate values returned to the client.

    Either override SaveChanges in the Business Entity and code it there or use ValidateData. You can get details about created eFather records based on standard ABL techniques like the ROW-STATE.

  3. Patrik Wikström
    Patrik Wikström avatar
    70 posts
    Registered:
    15 Oct 2018
    23 Oct 2019 in reply to Mike Fechner
    Link to this post

    Yes.

    Do you mean we could add the records to the child table in ValidateData (tracking changes = true etc.) when our business logic says so?

  4. Mike Fechner
    Mike Fechner avatar
    342 posts
    Registered:
    14 Sep 2016
    Answered
    23 Oct 2019 in reply to Patrik Wikström
    Link to this post

    Why shouldn't you? The ProDataset is the message send to the data access.

    You can do any (reasonable) change there. 

  5. Patrik Wikström
    Patrik Wikström avatar
    70 posts
    Registered:
    15 Oct 2018
    23 Oct 2019 in reply to Mike Fechner
    Link to this post

    Just asking to be sure! :)

    Thanks again Mike!

5 posts, 1 answered