3341 Posts in 982 Topics by 703 members
Page: 1 2
|Go to End||Next >|
25 March 2009 at 10:13pm Last edited: 25 March 2009 10:13pm
I have two statements of the type
$results=DataObject::get (" ", " ");
they contain exactly the same fields (but from different tables and may be with different SELECT criteria). How can I combine them (to implement UNION ALL)?
Thank you in advance. Victor
27 March 2009 at 2:50am
If you don't mind loading each set using a separate statement, then merging them in memory in SilverStripe, you could try DataObjectSet's merge method. (Remember that DataObject::get returns the resulting data set in a DataObjectSet.)
I think this would end up looking something like:
$results1=DataObject::get (" ", " ");
$results2.merge(DataObject::get (" ", " "));
Hope this helps,
27 March 2009 at 4:21am
It does not work, but huge thanks for pointing in the right direction:
and it works unless $results is empty in which case it bombs to
Fatal error: Call to a member function merge() on a non-object in ... on line ...
Then following the same tutorial I try
but it still bombs
Fatal error: Call to a member function exists() on a non-object in ... on line ...
Any suggestion? Thanks. Victor
27 March 2009 at 8:39am Last edited: 27 March 2009 8:40am
"exists" is a bit of a misnomer. DataObject will return nothing (false) if the query is empty. That always bugs me a little - breaks some of the chainability. A better way is to create an empty set first, then append to it. Then it doesn't matter if the results exist or not:
$ds = new DataObjectSet();
27 March 2009 at 9:57am
9 September 2010 at 4:22pm Last edited: 9 September 2010 8:21pm
This is great, would I be able to sort the data? for example order by date?
It's so simple just use:
$ds->sort('Date', 'DESC');// 2nd param not required ASC is default
30 September 2010 at 12:36am
I'd recommend using ->removeDuplicates after the "merge" as "merge" really means "append" using this function.
17 March 2011 at 6:35am
Okay, i have to merge two MemberObjects into one
Breeder extends Member
Owner extends Member
Dog has one Breeder and one Owner
The Owner isn't always a Breeder ( but can be)
The Breeder doesn't have to be the Owner (but can be)
At my DOG i have to;
- choose the Breeder (that's easy )
- choose the owner; 1) The Owner is not a Breeder (then it's easy, since the owners are members also)
2) The Owner is the same as the breeder ( well got that..leave owner empty and if-else)
3) The Owner is a Breeder, but not of this Dog.
So in my Dog object i have to make a 'Owner' DropDownField that shows the Breeders and the Owners in one list. Then my Dog has to know if his owner comes from the Owner DO or from the Breeder DO
I'm so lost (again,but ....learning )
Page: 1 2
|Go to Top||Next >|