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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

wrapping external tables in SS DataObjects


Reply


7 Posts   590 Views

Avatar
sergieboy

Community Member, 33 Posts

19 December 2011 at 10:19pm

Edited: 19/12/2011 10:20pm

I have the mySQL database for SS up and running. All tables OK and tables for DataObject created.
SS works fine.
Here's the situation : there is a external loader software which will load every 24Hr several tables from
a central DATAMART somewhere in the country and pull these tables in the MySQL database,
which is also the MySQL database for the SS installation. This loading mechanism works fine and several
external tables are updated in my SS MySQL database.
The goal is to use these external tables in my SS platform as DataObjects.
I found nothing in Ingo's book about this. Just until now, I read in some forum that it should be possible
to work with external tables, but never how.

How do i "wrap" these external tables into SS DataObjects ?

Avatar
swaiba

Forum Moderator, 1804 Posts

20 December 2011 at 2:30am

Hi,

Firstly to connect to external DB...

http://www.silverstripe.org/customising-the-cms/show/13692#post293308

Then to wrap items up into DataObjectSet...

http://www.silverstripe.org/data-model-questions/show/17245#post304677

Did you intend to view this data within DOM? The solution I give is to get the data into dataobject sets - mainly, I'd imageine for template parsing, nothing here to then view the data within the DOM (or MOdelAdmin) - that would be much harder.

Avatar
sergieboy

Community Member, 33 Posts

20 December 2011 at 3:01am

Edited: 20/12/2011 3:01am

I don't connect to an external DB.
The tables are succesfully created by the external loader software into the database used by SS.
The problem is that these databasetables should be a part of my local datamodel in SS.

There will be relationships between local defined tables and the external tables.

I have to use the tables as if it were dataobjects, created by SS, and manage it with DOM in the CMS.

Avatar
swaiba

Forum Moderator, 1804 Posts

20 December 2011 at 3:10am

In that case I suggest...
1) create DataObjects for these items (if they don't already exist)
2) create a script that transforms them from whatever format they are in into the SS structure

Avatar
sergieboy

Community Member, 33 Posts

20 December 2011 at 5:54am

...from whatever format they are into the SS structure.
That I do not understand.
I'm talking about a normal MySQL database table with a number of colums but which is filled by external loader.

Instead of creating objects and translating these into database tables, I want to do the reverse operation.
Just like you can with Java Persistance API (JPA).

Avatar
swaiba

Forum Moderator, 1804 Posts

20 December 2011 at 6:02am

Edited: 20/12/2011 6:03am

from whatever format they are into the SS structure.

two choices either 1) read then in to DataObjects and write them back to the database or 2) add the meta data silverstripe expects by altering the table and updating it.

I get what you want, but as far as i know that doesn't exist within the silverstripe ORM.

Avatar
sergieboy

Community Member, 33 Posts

20 December 2011 at 6:50am

I think only option 2 is possible. The purpose of all this is that changes in the corporate databases, spread all over the country,
are automatically propagated into the local copies (being the database tables in the SS MySQL databases).
If I read them into DataObjects and then write them back to the database, the "living link" is broken. If there is a change in the central corporate database table, which will be propagated automatically by the loader, it will not be reflected anymore in the database table which is connected with the object.

So my last chance is option 2. Being a rookie, is there any docu available somewhere ?

I thank you sincerely for your replies.