2

Having lots of problems working with SilverStripe after using namespaces on my custom code. The main problem is the naming convention SilverStripe uses to store namespaced classes:

A DataObject called Product with a Namespace of MyStore creates a table called Product\MyStore. The slash being a rather silly choice in naming convention since it is the escape sequence in MySQL.

The issue now is I am trying to manually drop an obsolete field from a table from the CLI and it is not possble to manually write a query that escapes such a table name.

describe Product\MyStore
describe "Product\MyStore"
describe 'Product\MyStore'
describe "Product\\MyStore"
describe 'Product\\MyStore'
describe Product\\MyStore

Yet this is just fine:

describe SiteTree

I must ask, are namespaces recommended in SilverStripe due to this? I'm very close to ripping all the namespacing out as how it's handled in 3.5 is quite counter-productive.

UPDATE: For future searches, to get around this in CLI you have to wrap the table names in backticks.

describe `Product\MyStore`

Although their use (or reasons that lead to them being used - such as poorly named tables) seems arguable in the MySQL community. I'll leave the question as it may still be valid on the naming convention side of things.

Community
  • 1
  • 1
Aaryn
  • 1,601
  • 2
  • 18
  • 31
  • SS4 is going to have the same naming scheme for DB-tables. So the backslashes are going to remain. *But* in SS4, you have the option to specify a custom table-name per DataObject (an option not available to SS3 users). – bummzack Feb 26 '17 at 08:24

1 Answers1

2

Short answer: no (EDIT: yes? - see below)

While it is possible, I would highly recommend you do not use namespaces in SilverStripe 3 but rather wait for SilverStripe 4. I myself have tried to use namespace on a couple of projects with SilverStripe 3.2 and had tons of troubles on all fronts, I eventually got it all to work, but it is/was not worth the effort. Therefore, I reverted to non-namespaced setups.

But there are good news, SilverStripe 4 is in alpha right now, and I have a good feeling that we will actually see a release relatively soon (a few month). I actually already have 2 projects using SilverStripe 4 in development, one is a community project that will go live in a few weeks. So if your project is either going to be in development for an extended period of time, or you are just willing to take the risk, you might want to consider using SilverStripe 4 already.

EDIT: Other people have pointed out that they had more success than I. Especially with the >=3.5. So I have to assume that compatibility with namespaces has been improved after I attempted to use them.

Zauberfisch
  • 3,870
  • 18
  • 25
  • Awesome thanks for the up front opinion. I've been getting the impression about namespacing not being worth-while myself. Heard good things about SS4 and keeping an eye on it. Unfortunately his project is to be released in less than a month. I should head over and try to prepare my code for 4 however. If it's possible. – Aaryn Feb 26 '17 at 00:44
  • 1
    I've always namespaced my 3.x projects. I'd be curious what troubles Zauberfisch is referring to. Many 3.x modules use namespaces, so IMO there's little basis for a firm "no," here. Optional, perhaps, but certainly not "no." – UncleCheese Feb 26 '17 at 07:28
  • I'm also using namespaces in 3.x, in modules and for projects. No issues so far… I'd be interested to know what stopped working when using namespaces. – bummzack Feb 26 '17 at 08:20
  • @bummzack are you also namespacing DataObjects in 3.x? – wmk Feb 26 '17 at 08:51
  • @wmk yes I am. Although only starting with 3.5 I think – bummzack Feb 26 '17 at 12:23
  • Hmm, interesting. What version of SilverStripe 3 did you use? Perhaps support has improved in later versions. One thing I remember in particular was that I had to subclass SSViewer to make it find my template files. – Zauberfisch Feb 26 '17 at 12:25
  • @bummzack I see. I've quickly updated my answer to reflect that others had more success. If you guys have more details to post please feel free to edit the answer. – Zauberfisch Feb 26 '17 at 12:30
  • I think this post could do with some references to prove your points. I actually think that namespacing should be encouraged where possible (i.e. not DataObjects or ModelAdmins, but everything else) – scrowler Feb 26 '17 at 20:02