Grouping Children

Using:
Coldbox 3.5
Adobe CF 9.1
Hibernate ORM

I have a parent object that can have many children objects. When I do
a modelService.get(id), I get the parent and all it's children by the
default nature of my ORM relationships. What I can't seem to find is
"if" there is a default Coldbox method that will allow me to group my
children objects by given properties or do I need to write a method in
my modelService to do what I want? Don't want to reinvent the wheel
here.

The system is an invoice / line item project where the system records
each item sold as a unique line item but when we create the invoice,
we sometimes want to group items of the same SKU.

Thanks

Erick

Erick,

Can you explain this a little clearer, I am not getting it, sorry:

What I can’t seem to find is

“if” there is a default Coldbox method that will allow me to group my
children objects by given properties

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Sure, not a problem.

I have a sales order object and each sales order has details (ie. line
items). Most of the time, the line items are different, but
occasionally we have a process that automates sales orders based on a
retail stores sales of the day. So if the store sold 10 of a given
item throughout the day, the system creates a sales order with those
10 line items.
However, I am able to pass a flag to my query that says "group the
common line items together so we see 1 line item with a count of
quantity and sum of the total amount of money made on those 10 items.

So when I do a salesOrderService.get(id)...I get my sales order and
all it's children based on the ORM relationships (ie. all the items
sold on that 1 given sales order). However, I was looking to see if
there was a way to group the sales order details by given properties
(ie. sku id, sum the qty, sum the total amount of money generated from
those items, etc). I was looking to see if there was any special
method that was part of Coldbox (similar to get() or findAllWhere())
that could group my line items (child objects) and not the parent
object(s).

I believe my best bet is going to be in building a custom criteria
query that can do things to the child associations as I see fit. Just
thought I'd ask before I reinvent the wheel.

Does that make sense?

Erick

I decided to roll my own query using criteriaBuilder but I sort of ran
into an issue that there may or may not be a work around.

in my salesOrderService file I do a newCriteria() and from there I do
the following...

var results = c.eq("docHeaderID",javacast("int",arguments.id))
        .createAlias('salesOrderDetails','sod').isEQ("sod.docHeaderID",arguments.id).maxResults(1)
          .withProjections(groupProperty="sod.sKUID",
sum="sod.detailQty,sod.extDollars")
      .list();

My problem lies in the projections and by doing a group and sum, all
that is returned is those 3 columns. The thing is I do need most of
the other 50 columns in the salesOrder table to be returned as well
and also it doesn't return it as an object, but as an array of arrays
with each child array being an array of my 3 columns.

I am a n00b to all this so it only makes sense that I'm overlooking
something or I'm trying to figure out how to NOT write the names of
the 50 other columns I need, but I guess if I have to, then I have to,
but I'm just looking to grow from others' knowledge. Any help to
streamline would be greatly appreciated.

Thanks

Erick

Yes, seems like a complex feature you need. Maybe a two step process where you can get all the IDs you need and then get all the object’s via the ID array via get(). However, without digging knee deep into your relationships I cannot comment if the criteria builder can do this for you.

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Luis, can you explain to me why using projections causes my results to
no longer be an object, but instead to get an array of arrays of the
data?

For each line item returned, I have an array index and inside that is
an array of all the columns being returned, but I have no way of
knowing which array index is which column.

Is there anyway around this?

Thanks