• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Filtering an array and computed values.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filtering an array and computed values.


  • Subject: Re: Filtering an array and computed values.
  • From: "Daniele Corti" <email@hidden>
  • Date: Fri, 6 Jun 2008 09:10:02 +0200

2008/6/6 Louis Demers <email@hidden>:
> Hi,
> Context: I want to display all parts whose inventory is not empty. I have a
> page that use a WODisplayGroup and a fetchspec built into EntityModeler to
> extract from the database some subcategories.
>
> Schema: My Part class has a one2many relationship to a Transaction class.
> Each transaction has a quantity field , positive when things are put in
> inventory and negative when taken out. Each Transaction also has a date
> field.
>
> In my lists, to display current inventory, I use a method on my Part class
> like
>
>        //
> __________________________________________________________________________________________________________________
>        public Number partCount() {
>                return (Number) transactions().valueForKey("@sum.quantity");
>        }
>        //
> __________________________________________________________________________________________________________________
>
>
> Question 1: I would like to display parts with the sum of transactions
> quantities is greater than 0
>

you need a qualifier for this..

> question 2: Eventually , I would like to further filter the transactions so
> that only those before a certain date are considered into the sum.
>

Also for this
>
> My current guess would be to manually remove parts by looping through the
> WODisplaygroup.allObjects() array and removing parts that do not qualify.
>
> Question 1.1: where would I filter this, in appendToResponse  where I
> currently call dg.fetch ?
>

No loops, I don't link them ;-P

> As for the second question, I could write a new partCount that would take a
> date as a parameter and loop through hall transactions into the arrays and
> only add quantities that qualify.
>

No, this is the hard way.

>
> Would those approach make sense and qualify as the WOWay of doing things ?
>
>

look, IMHO, you should work in this way:
 you should consider to set the qualifier of the WODisplayGroup before
dg.fetch (in appendToResponse), adding @sum.quantity >= 0 and/or date
>= yourDAte

For Example.

You have a qualifier in your WODIsplayGroup (or you add the array with
the objects fetched?) that query the DB for the result. YOu simply add
the Qualifiers for filtering the Objects you need, using
EOAndQualifier or EOOrQualifier.

hope this help.

--
Daniele Corti
AIM: S0CR4TE5
Messenger: email@hidden

--
Computers are like air conditioners -- they stop working properly if you open
WINDOWS

--
What about the four lusers of the apocalypse? I nominate:
"advertising", "can't log in", "power switch" and "what backup?"
--Alistair Young
 _______________________________________________
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

References: 
 >Filtering an array and computed values. (From: Louis Demers <email@hidden>)

  • Prev by Date: Re: ALCATRAZ! (Was: [OT] WOWODC Outing)
  • Next by Date: Re: Backtracking and Safari
  • Previous by thread: Filtering an array and computed values.
  • Next by thread: WWDC ticket to sell
  • Index(es):
    • Date
    • Thread