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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[SOLVED] Using DataObjects without DB Table


6 Posts   1999 Views


Community Member, 901 Posts

6 November 2009 at 11:35pm

Edited: 07/11/2009 3:10am

Hi all

In a project I'm creating temporary DataObjects, which are being built dynamically using the SQLQuery Class:

Since these DataObjects don't have to be persistent, I was wondering if there's a way to prevent the creation of a DB Table for my DataObject Class?

Any pointers are greatly appreciated.


121 Posts

7 November 2009 at 12:38am

I had a similar problem a few weeks ago where I wanted to create dataobjects which were session backed rather than db backed.

After playing around with ViewableData (the parent class) for a few days I came to the conclusion that the gulf between dataobjects and viewabledata was so large that it was easier to just use the db as a session store and clean things up later with a script.



Community Member, 901 Posts

7 November 2009 at 1:26am

Edited: 07/11/2009 1:27am

Hey Jamie

Thanks for your reply. The DB Table isn't to much of an issue, since it just sits there and does nothing in my case ;) I don't even have to clean things up, but the table is still redundant.
I was wondering why there isn't a table for "DataObject" itself... I think it might be possible to specify if a table should be created or not, I just wasn't able to figure out when and where this happens.


Community Member, 901 Posts

7 November 2009 at 2:18am


I figured it out. I had to override the requireTable method of the DataObject... no DB-Table is being created if I use the following code:

public function requireTable(){


Community Member, 283 Posts

7 November 2009 at 6:45pm

Edited: 07/11/2009 6:46pm

This is very interesting. Can I ask you guys what your guys were up to with unstored and/or transient objects?


Community Member, 901 Posts

7 November 2009 at 10:49pm

Hi dalesaurus

Sure. It's a rather simple thing that I did and could also have been solved otherwise (as always).
I have a page, that holds Events (DataObjects). This page only displays events from the current year. Events from previous years aren't displayed. To still be able to view older events, there should be an archive for every year. The year has to be selectable from the navigation (second level).

So that's what I did:
EventPage -> Holds all Event DataObjects
ArchivePage -> Pulls DataObjects from the EventPage

So far so good, no transient DataObjects till now.
I used them to create a dynamic Sub-Navigation with the available archived Years under ArchivePage. Therefore I overrode the Children method in the ArchivePage to return a dynamically created DataObjectSet with the available years. To achieve that, I made use of the SQLQuery class and the handy buildDataObjectSet method. See:

To make the entries in the set behave like a regular child page, I created a DataObject with all required methods like: Link, Title, MenuTitle, LinkingMode etc.
Since these DataObjects are created on request (depending on years where events took place), they don't need to be stored in the DB.

Not sure if my explanation was clear and/or of any use to you ;)