Web Connection
Parent child business objects
Gravatar is a globally recognized avatar based on your email address. Parent child business objects
  Doug
  All
  Jul 16, 2017 @ 08:25am

Looking for an example of performing CRUD on a standard parent/child relation using the wwbusiness class. Got the one to one done. Now need direction on linking children to master object and then displaying/saving. This would be similar to an order/orderdetail scenario.

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Rick Strahl
  Doug
  Jul 16, 2017 @ 09:06am

You can take a look at the music store sample in the Web Connection demos. Look at MusicStore.prg which is a relatively simple implementation but it should give you a good idea on direction.

There are a number of ways that this can be done.

  • Top level entity that controls children (musicstore does this)
  • Separate entities for parent and child list bus objects

Personally I try to use the first approach whenever possible because in most situations the child relationships are driven through the parent. You can then optionally have a child entity business object to perform special tasks.

The documentation has examples for the Separate entities approach using child business objects using the wwItemList class.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Doug
  Rick Strahl
  Jul 26, 2017 @ 08:50pm

So I added a method call to the parent load() method that gathers the detail records into an object on the parent (i.e. oParent.odata.children).

I display the Parent page with a htmldatagrid showing the children. This child grid has a couple editable fields.

My question is, how to capture the edits made on the page back into the child table?

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Rick Strahl
  Doug
  Jul 27, 2017 @ 10:30am

You have to manage that yourself, but there are these functions to help:

If you use the wwItemList class then there are methods that convert arrays to cursor and back.

Personally I've taken the former approach and add methods to load and save the child items which tends to be just as easy and makes for a cleaner object interface.

The examples I pointed in the previous message have examples on how to do this.

Just realized i didn't link the examples:

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Doug
  Rick Strahl
  Jul 27, 2017 @ 04:47pm

What I meant was, if on a webpage, a htmldatagrid has multiple rows and multiple editable fields, what is the best way to get (on server side) all the edited fields from the post at once, for all records in grid?

Should I wrap the grid inside a

, then use GetFormVarCollection() back on server side? How does one link the captured form collection back to the business object or table. Should I set the name/id to a combination of pk+fieldname when building the grid?

Doug

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Rick Strahl
  Doug
  Jul 27, 2017 @ 10:03pm

I wouldn't build a UI like that not with server rendered HTML. You generally want to avoid grid data entry in the browser unless you build a true client side application and you just send data back and forth using a REST service in which case you can use a client side grid component like jsGrid or if you're using Angular perhaps something like ng-grid. With client side grids you can edit the data and then send the entire edited data back to the server as a data and then figure out how to update the database from the edited data (some sort of merging or wholesale update).

For server side only, a better approach is to either drill in for a detail edit form, or pop over an editable item form that you then submit. If you're really set on doing an editable grid there's a weblog entry that talks about how to capture bulk input fields from a grid, but it's a pain in the butt...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Doug
  Doug
  Jul 28, 2017 @ 11:36am

I'll think about the drill in edit or pop over form. Might be a pain for users if they need to make a lot of changes. I'll also check out the referenced article.

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Doug
  Doug
  Jul 28, 2017 @ 12:09pm

Ok, I'll bite. Curious, what are the pitfalls of making a data entry grid using server rendered HTML?

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Doug
  Rick Strahl
  Jul 28, 2017 @ 12:35pm

Ok, I'll bite. Curious, what are the pitfalls of making a data entry grid using server rendered HTML?

Might be beneficial to someone else thinking of editable grids.

Doug

Gravatar is a globally recognized avatar based on your email address. re: Parent child business objects
  Rick Strahl
  Doug
  Jul 29, 2017 @ 03:43pm

Like I said - you can do this but typically you do it with a client centric page, not through a server centric page. Or - you edit one record at a time and save that data immediately back to the server with REST service calls (ie. when you move to a new row). Totally doable, but not automated.

There are grids you can use and they provide the hooks and events to let you know when you navigate off etc. but you have to wire the logic to handle those events and updates that data yourself.

+++ Rick ---

© 1996-2024