I have a many-to-many relationship between Author and Book.
Author <-->> AuthorBook <<--> Book
Each with a string attribute,
Name of an Autor and Title of a Book.
I want to be able to search fields on both entities.
The search string is in wordToSearch.
Searching through this mailing list, I was able to adapt this code for an "OR" search.
My Problem:
wordToSearch is "franco"
I can find an Author name "Bob" who wrote a Book titled "Franco"
I can't find an Author name "Franco" without any book assign to him.
If I assign a Book titled "racing" to Author "Franco",
or If I remove qual2 from the EOOrQualifier then the Author entity with name "Franco" shows up.
I am new to WebObject and help would be very appreciated.
Thank you
Franco
public WOComponent goSearch()
{
editingContext = session().defaultEditingContext();
String wordToSearch = this.motAChercher();
EOSortOrdering nameSort = new EOSortOrdering("name",EOSortOrdering.CompareCaseInsensitiveAscending);
NSMutableArray sortOrderings = new NSMutableArray();
sortOrderings.addObject(nameSort);
if (wordToSearch == null)
{
listOfAuthors = new NSArray(editingContext.objectsWithFetchSpecification(authorFetch));
}
else
{
wordToSearch = "*" + wordToSearch + "*";
EOKeyValueQualifier qual1 = new EOKeyValueQualifier("name",
EOQualifier.QualifierOperatorCaseInsensitiveLike,
wordToSearch);
EOKeyValueQualifier qual2 = new EOKeyValueQualifier("books.title",
EOQualifier.QualifierOperatorCaseInsensitiveLike,
wordToSearch);
EOOrQualifier orClause = new EOOrQualifier(new NSArray (new Object[] { qual1, qual2 } ));
EOFetchSpecification wordToSearchFetchSpecification = new EOFetchSpecification("Author", orClause, sortOrderings);
listOfAuthors = new NSArray(editingContext.objectsWithFetchSpecification(wordToSearchFetchSpecification));
}
return null;
}