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

how to use datalist? how can you edit it? does it clone?


Reply


5 Posts   734 Views

Avatar
Nicolaas

Forum Moderator, 213 Posts

21 January 2013 at 1:55pm

Edited: 21/01/2013 1:55pm

Please have a look at this:

http://www.sspaste.com/paste/show/50fc8a072fc12:

01   <?php
02   
03   $myDataList = MyDataObject::get();
04   
05   //option 1
06   $myDataList = $myDataList->Filter("MyField", 1);
07   
08   
09   //option 2
10   $myDataList->Filter("MyField", 1);
11   
12   return $myDataList
13   
14   // QUESTION: does option 1 return the same as 2? Is that something that is different between 3.0 and 3.1?

This is a really important question. My answer is that option 1 is not the same as option 2. This surprises me and does not seem intuitive.

I would love to hear some thoughts on this.

Nicolaas

Avatar
simon_w

Forum Moderator, 474 Posts

21 January 2013 at 9:27pm

You can think of DataLists as immutable. In 3.0, this wasn't always the case (but is in this one). This means that methods that alter the representation of the list (so things like filter, exclude and sort though not things that alter the data like add and remove) return new instances of the list without changing the current variable.

Avatar
Nicolaas

Forum Moderator, 213 Posts

21 January 2013 at 10:12pm

Edited: 21/01/2013 10:15pm

Simon, thank you very much for the reply. Disappointing it is so unclear (not your answer, the API itself).

Avatar
Nicolaas

Forum Moderator, 213 Posts

22 January 2013 at 9:22am

Thanks again Simon for your answer, also see: https://github.com/silverstripe/sapphire/pull/1020 for more information.

Avatar
Nicolaas

Forum Moderator, 213 Posts

22 January 2013 at 9:39am

also see: https://groups.google.com/forum/#!topic/silverstripe-dev/DzwcedAy6AQ