Form with a primary BO with two registers


Author
Message
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Hi, I need to save two records on a "primary" object,, 1 record related to some child BOs and the 2nd record to another childs.

If I have a parent-child relation it only will update the child pk with the first parent record pk?

How can I set that I like to set the 2nd record pk to be the parent pk of child BO registers?

I hope that It can be understand (sorry for me bad english)

thanks
Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Fabian,

Fabian R Silva, - (8/3/2012)
I hope that It can be understand (sorry for me bad english)

Your English is pretty good so that is not a problem Tongue  Your situation on the other hand its a bit awkward BigGrin  Probably you can get away with it by having 2 instances of the Parent BO and register their parent child BOs. 

Would you care to elaborate what kind of data entry design are you working on that would require you to add 2 parent records at the same time (I guess not related to each other) plus their child records?

Edhy Rijo

Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Hello Edhy, thanks for reply.

my project have the classic order - items (a little ERP system), but in my design the same table is used for invoices and payments

When the invoice is billed entirely 100% in cash, I have to save two records, one with the invoice and the other with the payment

both of them have child bo's that are diferent
they're related with another table that maintain the "current account balance", this table have the relation of invoices and payments (can be more than 1 record of payment for 1 invoice and vice versa)

at this time still not implemented that part of "partial payment", only can pay the invoice completely, for that I like to save the payment record on the same table with the related childs.



your recommedation of create two BOs, one for each parent register seems to be a good solution, to make this I have to overwrite the form's save method to manually control the transaction, then I can save the first BO with the first record (invoice) , if needed replace something on childs of first BO, then save the 2nd parent record (the payemnt) with 2nd BO and then replace if needed something on childs of that 2nd BO (childs of payment) and commit transaction.

this can be the best approach to save? 
I tried to use the framework automations all I can but that seems to be a candidate to make some stuff manually.

Thanks
Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Fabian,

Fabian R Silva, - (8/3/2012)
this can be the best approach to save? 
I tried to use the framework automations all I can but that seems to be a candidate to make some stuff manually.


Thanks for the explanation, it makes sense now Smile even though I would have 2 tables one for Invoice and one for Payments.

StrataFrame Save logic can take care of everything for you, all you need to do is to have the BOs properly related.   I would do something like this:
  1. In your case the Invoice and Payments come from the same BO let's call it MasterBO, you will drop 2 instances of this BO
  2. Rename them to something like InvoiceBO1 and PaymentsBO1
  3. Manually in the form's Load() or better yet in the OnLoad() event, manually Register the relationship between these 2 BO, SF should treat them as 2 different tables and once you create a new record in PaymentsBO1 it should updated the FK field registered manually.
  4. Register all other FK relationship between their respecive child BOs and when you save any of the child or parent record, SF will start saving all new records starting from the Parent BOs to get the proper FK for the child BOs.
  5. Of course I would use a custom Save method if you need this saving to be part of a transaction which I would recommend if your business rules logic requires it.


Edhy Rijo

Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)StrataFrame User (241 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
thanks, great for the explained detail, you mention "manually register the relationship", just today I read something about "RegisterForeignKey", 
RegisterForeignKey is the method to do the parent - child relationship and keep auto-fk populate from primary bo pk?

how I can set that 1st I like to save the "Invoice" BO and then "Payment" BO to make it the 2nd register every time?

thanks again.
Edited 12 Years Ago by Fabian R Silva, -
Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Fabian,

Yes, you are correct about the BO.RegisterForeinKey() method.  For a clear explanation check this Post by Trent where it is explained much better.

how I can set that 1st I like to save the "Invoice" BO and then "Payment" BO to make it the 2nd register every time?

Well when using
the BO.RegisterForeinKey() method, SF will take care of that for you, not matter which BO triggers the saving, it will go up to the parent bo to grab the PK.  But in your case, it would be better for you to manage this logic yourself, create your own Save method using a BusinesLayer Transaction so you can have full control on how information is saved.

Once you have this done, you will be amazed on how powerful and flexible SF Business Objects are.  Using the 2 BO instances will allow you to handle each record based on their transaction type (ex: Invoice or Payment) so you will always know which record you are managing.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search