ERXExistsQualifier to the rescue!
> On Jan 29, 2015, at 9:12 AM, Theodore Petrosky <[email protected]> wrote:
>
> The Person has an instrument. The Book has an instrument. so the popup list
> should be only those books with the same instrument.
To match instances of book that are for an instrument that is related to a
given person:
If this is your model:
Person <<-> Instrument <->> Book
Then:
public static synchronized EOQualifier thatAreForPersonByInstrument(Person
person) {
return
Book.INSTRUMENT.dot(Instrument.PERSONS.containsAnyObjectSatisfying( person ) );
}
OR If this is your model (seems more likely):
Person <->> PersonInstrument <<-> Instrument <->> InstrumentBook <<-> Book
Then:
public static synchronized EOQualifier thatAreForPersonByInstrument(Person
person) {
return Book.INSTRUMENT_BOOKS.containsAnyObjectSatisfying(
InstrumentBook.INSTRUMENT.dot(
Instrument.PERSON_INSTRUMENTS.containsAnyObjectSatisfying(
PersonInstrument.PERSON.is( person ) ) ) );
}
> But one layer deeper. a Person is assigned to one or many Shows. the Books
> belong to a show. So if Person 1 only play one show and plays viola (I know
> its a handicapped Person), the popup list only shows that one book as
> available to assign.
Person <->> ShowPerson <<-> Show <->> Book
public static synchronized EOQualifier thatAreForPersonByShow(Person person) {
return Book.SHOW.dot(
Show.SHOW_PERSON.containsAnyObjectSatisfying(
ShowPerson.PERSON.is( person ) ) );
}
And to combine them together:
public static synchronized EOQualifier thatAreForPerson(Person person) {
return Book.thatAreForPersonByInstrument( person )
.and( thatAreForPersonByShow( person ) );
}
By making these static methods, not only can you use that in your fetch
specification, but you can also use it to check to see if a book is available
to a person (for example, in validateForSave, or wherever else):
public boolean isVisibleTo(Person person) {
return thatAreForPerson(person).evaluateWithObject(this);
}
Dave
—————————————————————————————
WebObjects - so easy that even Dave Avendasora can do it!™
—————————————————————————————
David Avendasora
Senior Software Abuser
Nekesto, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]