Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Decorating DataObjectSet?

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

Page: 1
Go to End
Author Topic: 459 Views
  • fatlewis
    Avatar
    Community Member
    1 Post

    Decorating DataObjectSet? Link to this post

    Hey, this is my first post so be nice!

    A site that I've been working on has portfolio pieces stored as DataObjects, each with a relevant image. These are getting pulled to the template and shown in a widget, but the aim has been to show a random 4 logos, rather than 4 from a specifically sorted set.

    Being somewhat averse to using mySQL's "RAND()" function in a query, I figured the best way of doing it would be to initialize the full set of DataObjects and then use a shuffle function (which for some reason isn't in the core DataObjectSet class). Unfortunately decorating the class and using:

    public function Shuffle() {
       shuffle($this->owner->items);
    }

    Throws up the error:

    [Notice] Indirect modification of overloaded property DataObjectSet::$items has no effect

    I wondered if anyone could explain why this was and how one would go about decorating the class correctly (if at all)?

    (FYI, I managed to achieve what I wanted by extending DataObjectSet, but wondered why decorating wasn't working)

    Cheers!

  • dizzystuff
    Avatar
    Community Member
    93 Posts

    Re: Decorating DataObjectSet? Link to this post

    Hi fatlewis! Could it just be that you're missing the ( ) at the end of ->items?

    shuffle($this->owner->Items());

    This isn't my first post but usually I'm here asking questions not answering them (I'm procrastinating pretty epically right now so figured I'd try to be useful at least) so please be nice back if this is doesn't do the trick

    EDIT: just saw the date on the post heh. ah well. hope it helps someone.

    459 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.