21277 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1573 Views |
-
[SOLVED] Using DataObjects without DB Table

6 November 2009 at 11:35pm Last edited: 7 November 2009 3:10am
Hi all
In a project I'm creating temporary DataObjects, which are being built dynamically using the SQLQuery Class:
http://doc.silverstripe.org/doku.php?id=sqlquery#transforming_a_result_to_dataobjectsetSince 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.
-
Re: [SOLVED] Using DataObjects without DB Table

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.
Jamie
-
Re: [SOLVED] Using DataObjects without DB Table

7 November 2009 at 1:26am Last edited: 7 November 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. -
Re: [SOLVED] Using DataObjects without DB Table

7 November 2009 at 2:18am
Hello
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(){
DB::dontRequireTable($this->class);
} -
Re: [SOLVED] Using DataObjects without DB Table

7 November 2009 at 6:45pm Last edited: 7 November 2009 6:46pm
This is very interesting. Can I ask you guys what your guys were up to with unstored and/or transient objects?
-
Re: [SOLVED] Using DataObjects without DB Table

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 EventPageSo 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: http://doc.silverstripe.org/doku.php?id=sqlquery#transforming_a_result_to_dataobjectsetTo 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 ;)
| 1573 Views | ||
|
Page:
1
|
Go to Top |



