I am learning about subclassing EOs.
I have an entity; Contact
and three subclasses Employee, VendorContact, MediaContact
the qualifiers are: isEmployee (bool) isVendorContact (bool) isMediaContact
(bool)
ie:
isEmployee <> 0
isVendorContact <> 0
isMediaContact <> 0
testbed=# select * from t_contact;
c_first_name | c_last_name | id | c_is_vendor_contact | c_is_media_contact |
c_is_employee
--------------+-------------+----+---------------------+--------------------+---------------
Ted | Petrosky | 1 | t | t | f
Bill | Simpson | 2 | t | t | t
Harold | Wall | 3 | f | t | f
so I set up a test page simple with ordered lists wrapped in WOReps
and queried the backend to populate the NSArrays:
theEC = ERXEC.newEditingContext();
vendors = VendorContact.fetchVendorContacts(theEC,
VendorContact.IS_VENDOR_CONTACT.eq(true), null);
employees = CompanyEmployee.fetchCompanyEmployees(theEC,
CompanyEmployee.IS_EMPLOYEE.eq(true), null);
mediaContacts = MediaContact.fetchMediaContacts(theEC,
MediaContact.IS_MEDIA_CONTACT.eq(true), null);
System.out.println("Media List " + mediaContacts);
System.out.println("Employees List " + employees);
System.out.println("Vendor List " + vendors);
After I ran my app it barfed at me:
Error: java.lang.IllegalArgumentException: While trying to set the field
"anEmployee" on an object of type com.eltek.components.Main we expected a
com.eltek.model.CompanyEmployee but received a com.eltek.model.VendorContact
with a value of <com.eltek.model.VendorContact pk:"1">. This often happens if
you forget to use a formatter.
Now I understand that I can not fetch these entities in a single EC as any
contact could be a member of any or all subclasses.
Did I miss something (a property maybe [since everything is a property]) or
must I use multiple ECs in this case? Obviously, that was my solution, set up a
different EC for each subclass. Then all is well (but is it?).
Ted
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]