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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

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


Go to End


5 Posts   1506 Views

Avatar
Nicolaas

Forum Moderator, 224 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
(deleted)

Community Member, 473 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, 224 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, 224 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, 224 Posts

22 January 2013 at 9:39am