3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 775 Views |
-
SS3 DataObject merge - SOLVED

23 August 2012 at 3:26am Last edited: 23 August 2012 3:26am
I have two DataObject-Sets:
$set1 = DataObject::get('Visualisierung','Favorit = 1', 'RAND()');
$set2 = DataObject::get('Visualisierung','Favorit = 0', 'RAND()');Now i want to merge these two to iterate them later in the template.
In SS 2.4 The Following worked:$set1->merge($set2);
Now with SS3 i get the following error Message:
[User Error] Can't call DataList::merge() because its data comes from a specific query.What is my error here?
-
Re: SS3 DataObject merge - SOLVED

23 August 2012 at 3:34am
If i use
$newSet = DataObject::merge($set1, $set2);I get an Error that the expected Object Class is wrong. (It expects the Page Class but i wanna merge pulled DataObjects)
-
Re: SS3 DataObject merge - SOLVED

23 August 2012 at 6:18pm
With 3.0 and the lazy-loading ORM, you can't merge two DataLists. As your case is simple, you can simply use $set = Visualisierung::get()->filter('Favorit', array(1, 0))->sort('RAND()');
-
Re: SS3 DataObject merge - SOLVED

23 August 2012 at 8:39pm
Unfortunately that does not produces the result i want. It just Randomizes ALL the Objects...
I try to achieve the following:
The First few Objects should be all "Favorite=1" in Random Order.
Followed by all Objects with "Favorite=0" in random OrderI think i will have to handle this in the template now if it is no more possible with the ORM... (Seems it has less features than before?)
-
Re: SS3 DataObject merge - SOLVED

23 August 2012 at 8:43pm
In that case, you want Visualisierung::get()->filter('Favorit', array(1, 0))->sort('Favorit', 'desc')->sort('RAND()');
If you really need to run them separately then merge, you can use something like:
$set = new ArrayList;
foreach(Visualisierung::get()->filter('Favorit', 1)->sort('RAND()') as $obj) $set->push($obj);
foreach(Visualisierung::get()->filter('Favorit', 0)->sort('RAND()') as $obj) $set->push($obj);
return $set;which is pretty much what was happening in 2.4.
-
Re: SS3 DataObject merge - SOLVED

23 August 2012 at 9:21pm Last edited: 23 August 2012 9:37pm
I really needed to run them seperately.
object-> push works perfect!
On http://klarbild.probiermau.ch/ you can see how i use it...
First are all "Favorite=1" Objects(Picture shown) in Random Order.
The last two Rows are all "Favorite=0" Visualisierung Objects in Random Order.Simon_w you are officially my hero for today!
Thanks a lot for your kind help!
| 775 Views | ||
|
Page:
1
|
Go to Top |
