Re: Sort Approach in Many to Many Subset
Re: Sort Approach in Many to Many Subset
- Subject: Re: Sort Approach in Many to Many Subset
- From: Ramsey Gurley <email@hidden>
- Date: Tue, 21 May 2013 10:31:35 -0700
On May 21, 2013, at 10:30 AM, Ramsey Gurley wrote:
> Depending on customer counts, doing this in memory may not be very efficient. If you have a large number of customers, you may want to set up a stored procedure and let the database do it. Depending on how the tables are arranged, you may be able to do it with a single select, but it may not be something you can construct easily with an EOFetchSpecification.
>
> I'd just go ahead and set that up in the first place, because eventually, customers will grow to the point it will be necessary anyway. To get at your actual question though, you could do something like
>
> //In Customer.java
> private transient BigDecimal amount;
>
> public void loadOrderAmountForStore(Store store) {
> amount = ...
> }
>
> public BigDecimal amount() {
> return amount;
> }
>
>
> NSArray<Customer> customers = ...
> Store store = ...
> NSSelector<BigDecimal> sel = new NSSelector<BigDecimal>("loadOrderAmountByStore", new Class[]{Store.class});
That should be NSSelector<Void>, but you get the idea.
> customers.makeObjectsPerformSelector(sel, new Object[]{store});
> customers = ERXS.desc("amount").sorted(customers);
> return customers.objects(new NSRange(0, 5));
>
> Ramsey
>
> On May 21, 2013, at 10:08 AM, James Cicenia wrote:
>
>> Actually, my question revolves around sorting a method that needs a parameter.
>>
>> For instance, I have an EO with the calculated value:
>>
>> totalOrderAmountByStore(Store store);
>>
>> How would you notationally write a sort to sort those EOs by that method?
>>
>> make sense?
>>
>>
>> On May 21, 2013, at 11:41 AM, Jesse Tayler <email@hidden> wrote:
>>
>>>
>>> well, I'm not certain I understand your question but if your method derives that totalOrderAmount then you'd have to sort that in memory after getting a reasonable number of objects from another fetch.
>>>
>>> often times in these situations I setup a kind of calculated integer and store the result right on the User table, as an integer, so I can order objects based on that result.
>>>
>>> you'd need to identify the places (likely relationships) where operations might possibly change that number, and recalculate that result again at runtime -- again, you'd be storing and saving the resulting number on the user table for later sorting from the database.
>>>
>>> or maybe your issue is something else?
>>>
>>>
>>> On May 21, 2013, at 12:33 PM, James Cicenia <email@hidden> wrote:
>>>
>>>>
>>>> I have the following:
>>>>
>>>> customer <<---->> stores.
>>>>
>>>> I want the top five customers by order total for a store.
>>>>
>>>> I wrote a method:
>>>>
>>>> customer.totalOrderAmountByStore(Store store);
>>>>
>>>> What is the best way to sort that?
>>>>
>>>> Is there some cool ERXKEy? Make an abstract Entity in my Model?
>>>>
>>>> Wondering
>>>> James
>>>> _______________________________________________
>>>> Do not post admin requests to the list. They will be ignored.
>>>> Webobjects-dev mailing list (email@hidden)
>>>> Help/Unsubscribe/Update your Subscription:
>>>>
>>>> This email sent to email@hidden
>>>
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden