Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Data Object write including $has_many


Go to End


1393 Views

Avatar
Sh33pDawg

Community Member, 2 Posts

31 March 2016 at 4:20pm

Hi

I am writing a Controller so that I may command line control the read of an XML file and parse that information into a database. I've created the DataObject and this has a number of $has_many relations; in order to keep the normalisation of the tables to an optimum. i.e. the XML will be a purchase order containing header information, a possible multiple of address details (for delivery to, or from, or billing etc), multiple line items, multiple potential charges etc.

I have no influence in how this PO is constructed; it is a delivered by 3rd parties with a strict data structure (re. EDIFACT 850).

Effectively the base information will be contained within a table to which other tables are related; which in turn contain those elements that may have one or more sets of data.

A $has_many relation; AFAIK (N.B. still learning!)

My question concerns best practice when constructing the contents of the DataObject for write:

  • would one include the records for the $has_many tables within the same DataObject?
  • how would a single encapsulated DataObject pertaining to multiple tables look in an example?
  • failing that should one construct multiple DataObject write instances utilising the record ID returned from the main table write, thereby manually constructing the relational setup?

Please forgive my ignorance but all the example I am finding relate directly to templates and tables and I'm attempting to use the SS environment not only as a front end GUI interface but also a toolbox for parsing data in the background; but on a learning curve against a deadline!!

All help and understanding is sincerely appreciated.

Thank you in advance.