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.

Data Model Questions /

defining a dataobject for a table not created by silverstripe


Reply


402 Views

Avatar
MJA

Community Member, 16 Posts

24 May 2013 at 1:14am

Hello Guys

This is quite involved, so please bear with me.

I am trying to read a table created outside of Silverstripe (see attached clip). However, SS is not recognising the data object.

The site is running off of a MicroSoft database rather than the more usual MySQL database, but this does not seem to be a problem. When I create data objects in SS and run mysite/dev/build the data tables appear in the database exactly as I would expect.

In order for SS to read the table in obviously needs a definition for it in the data model. To give it this I created a DataModel extension as normal:

   class DocEditorAssets extends DataObject {
   
      public static $singular_name   = 'Document Editor Asset';
      public static $plural_name      = 'Document Editor Assets';
      
      public static $db = array (
         'asset_id'         => 'Int',
         'name'            => 'Varchar(255)',
         'version'         => 'Float',
         'updated'         => 'SS_Datetime',
         'text'            => 'Text',
         'updated_by'      => 'Varchar(255)',
         'category'         => 'Varchar(50)',
         'status_id'         => 'Int',
         'rejected_reason'   => 'Varchar(2000)',
         'locked_by'         => 'Varchar(255)'
      );
   
   }   // end class DocEditorAssets

and then ran mysite/dev/build

I had expected SS to pick up the definition, find that the table already existed and proceed as normal, possible appending a couple of fields to the table (ClassName, Created, etc). However, what actually happened was -- nothing at all.

There was no entry in the dev/build listing which would indicate that SS had picked up the definition and tried to create and/or modify the table (i.e. it did not list DocEditorAssets as I would have expected).

I cannot understand why this should be. There is, as far as I can see, nothing wrong with the definition and, apart from being created by an external system, there is nothing unusual about the table.

Any help you can offer will be greatly appreciated.

Thanks in advance.

Attached Files