Sub-classing Relation Lists (Components)

30 views
Skip to first unread message

Jeremy Shipman

unread,
Apr 21, 2013, 8:09:54 PM4/21/13
to silverst...@googlegroups.com
Can you give your opinion on my approach to changing the type of list
automatically produced for a has_many relation?

My example is: $order->Items() , produces a OrderItemList, instead of a
HasManyList

see:
https://gist.github.com/jedateach/5431637

Getting a result set in a custom implementation of HasManyList, means I
can change, and add extra functionality for display, and calcuation. For
example, I've overridden the sum function to include summing fields on
joined objects.

However, the way I have implemented this subclassing seems untidy/hacky.
Is there, or should there be a nicer way of sub-classing relation lists
that are automatically created?

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Apr 22, 2013, 3:55:30 AM4/22/13
to silverstripe-dev
It looks great.

What lines do you think needs the most tidying up / cleaning? If I look at these lines:

$components = parent::getComponents($componentName, $filter = "", $sort = "", $join = "", $limit = null);
if($componentName === "Items" && get_class($components) !== "UnsavedRelationList"){
$query = $components->dataQuery();
$components = new OrderItemList("OrderItem", "OrderID");
if($this->model) $components->setDataModel($this->model);
$components->setDataQuery($query);
$components = $components->forForeignID($this->ID);
}

Then i sort of understand what is going on - but I am not sure what you could change without a detailed knowledge of these core functions.

It appears to me that the core code perhaps could be made more "generic" so that you could achieve the above in less / clear lines?

Nicolaas




--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-dev+unsubscribe@googlegroups.com.
To post to this group, send email to silverstripe-dev@googlegroups.com.
Visit this group at http://groups.google.com/group/silverstripe-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.








Jeremy Shipman

unread,
Apr 22, 2013, 6:04:09 PM4/22/13
to silverst...@googlegroups.com
> It appears to me that the core code perhaps could be made more
> "generic" so that you could achieve the above in less / clear lines?
My thoughts exactly.

It would be nice if I could just say (in code), "use OrderItemList
instead of HasManyList"
Reply all
Reply to author
Forward
0 new messages