Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObject specifing a connection name

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

Page: 1
Go to End
Author Topic: 225 Views
  • Alexw
    Avatar
    Community Member
    2 Posts

    DataObject specifing a connection name Link to this post

    Hello,

    I have a suggestion about the features of DataObjects. What about adding the ability to specify a connection name that a specific DataObject should need to use. There are situations that some tables are managed by Silverstripe but are located somewhere else or at different database name.

    _config.php:

    $db = new MySQLDatabase(array(
          'server' => 'localhost',
          'username' => 'myUsername',
          'password' => 'myPassword',
          'database' => 'myDatabase'
       ));
    DB::setConn($db, 'external');

    code/MyDataObject.php

    class MyDataObject extends DataObject
    {
       public static $conn = 'external';

       public static $db = array(
          'IsActive' => 'Boolean'
       );

       public function getCMSFields()
       {
          return new FieldList(
             new CheckboxField('IsActive')
          );
       }
    }

    Kind regards,
    Alexw

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: DataObject specifing a connection name Link to this post

    Hi,

    Thanks for willing to contribute to SilverStripe! Propositions won't always be picked up from within these forums though. Please check out this documentation on how to contibute: http://doc.silverstripe.org/framework/en/trunk/misc/contributing/code

    In the mean time, as to multiple db connections, there are some solutions/workarounds around. For example: http://www.silverstripe.org/customising-the-cms/show/13692

    I remember a discussion about this a short while ago in the core developers group (https://groups.google.com/d/forum/silverstripe-dev) but I can't seem to find it just now...

    Basically afaik you cannot work with multiple connections at the same time, but you can switch between connections if need be.

    Martine

    225 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.