Thank you, I ended up in a to-many relationship simillar to you guys. Amiel
On Fri, Aug 28, 2009 at 2:45 PM, Andri vonAllmen <[email protected]>wrote: > Hi Amiel, > > As already mentioned, the database has to make the assuption, that > there may be 0..n 'State' records for a 'Seo' record. Hence, you have to > handle the relationship like a to-many relationship. > > In other words: First, all 'State' records for a given 'Seo' record > have to be fetched, second, the returned array has to be "analysed". > Since you guarantee that there is only one 'State' record for a given > 'Seo' record, the array returned will always contain one object (or no > one if there is no 'State' set for the 'Seo' or multiple 'State' records > if your guarantee is not met). > > Something like this should help: > > // fetches all 'State' records for a given 'Seo' record > NSArray states() { > return editingContext().objectsWithFetchSpecification(new > EOFetchSpecification("State", > EOQualifier.qualifierWithQualifierFormat("seo = %@", new NSArray(this)), > null)); > } > > // checks if there is really just one 'State' record for a given 'Seo' > record and returns this one respectively null if there is no 'State' > record or more than one 'State' record available for the given 'Seo' > record > State state() { > NSArray states = states(); > if ( states.count() == 1) { > return states.objectAtIndex(0); > } > return null; > } > > Regards > Andri von Allmen > > >>> Amiel Montecillo <[email protected]> schrieb am Freitag, 28. > August 2009 um > 06:18 in Nachricht > <[email protected]>: > > I would agree with you that this relationship is not guaranteed to be > a > > to-one relationship. However, I have coded my app in a way that I > can > > guarantee that it is a to-one relationship. > > > > The only thing is I get that exception when I try to update > state.seo > > properties. > > > > Then I tried to remove the class property of Seo.state(). The > relationship > > is still in tact but I can no longer access seo.state(). This seems > to work, > > but if there is a way that I can keep Seo.state() as a class property > of Seo > > and not get the exception on an update, that will really make my > day. > > > > Thanks Ken for the insight. Anyone else has some other idea? > > > > Amiel > > > > On Fri, Aug 28, 2009 at 12:01 PM, Ken Anderson > <[email protected]>wrote: > > > >> This relationship is not guaranteed to be to-one, since there could > be many > >> States that match the Seo's ID. > >> > >> The way I deal with this is to model it as a to-many relationship, > and > >> write methods in the EO that set/get, enforcing the to-one concept. > >> > >> > >> > >> On Aug 27, 2009, at 10:28 PM, Amiel Montecillo wrote: > >> > >> Hello, > >>> > >>> I have a to-one relationship that is giving me problems when > updating the > >>> destination entity. > >>> > >>> class Seo > >>> { > >>> id; <- PK > >>> title; > >>> description; > >>> state() <- reverse to-one relationship to State > >>> } > >>> > >>> class State > >>> { > >>> id; <- PK > >>> name; > >>> seoid; <- FK to Seo (id) > >>> seo(); <- optional to-one relationship to Seo > >>> } > >>> > >>> When I first enter an Seo to a State, all seems fine, all > properties of > >>> Seo are saved and are related to the corresponding State. But then, > when I > >>> update it I get this exception. > >>> > >>> > >>> Unable to map destination State for relationship state in entity > Seo. To > >>> one relationships must be joined on the primary key of the > destination. > >>> java.lang.IllegalArgumentException: Unable to map destination State > for > >>> relationship state in entity Seo. To one relationships must be > joined on > >>> the primary key of the destination. > >>> at > >>> > > > > com.webobjects.eoaccess.EORelationship._sourceRowToForeignKeyMapping(EORelati > > onship.java:1134) > >>> at > >>> > > > > com.webobjects.eoaccess.EORelationship._foreignKeyForSourceRow(EORelationship > > .java:1148) > >>> at > >>> > > > > com.webobjects.eoaccess.EODatabaseContext._objectFaultWithSnapshotRelationshi > > pEditingContext(EODatabaseContext.java:2346) > >>> at > >>> > > > > com.webobjects.eoaccess.EODatabaseContext._fireDeferredFaultWithSourceObject( > > EODatabaseContext.java:2401) > >>> at > >>> > > > > com.webobjects.eoaccess.EOAccessDeferredFaultHandler.createFaultForDeferredFa > > ult(EOAccessDeferredFaultHandler.java:49) > >>> at > >>> > > > > com.webobjects.eocontrol.EOCustomObject.willReadRelationship(EOCustomObject.j > > ava:1279) > >>> at > >>> > > > > er.extensions.eof.ERXGenericRecord.willReadRelationship(ERXGenericRecord.java > > :358) > >>> at > >>> > > > > com.webobjects.eocontrol._EOMutableKnownKeyDictionary$Initializer$_LazyGeneri > > cRecordBinding.valueInObject(_EOMutableKnownKeyDictionary.java:614) > >>> at > >>> > > > > com.webobjects.eocontrol.EOCustomObject.storedValueForKey(EOCustomObject.java > > :1634) > >>> at > >>> > com.webobjects.eocontrol.EOCustomObject.snapshot(EOCustomObject.java:525) > >>> at > >>> > > > > com.webobjects.eocontrol.EOEditingContext.objectWillChange(EOEditingContext.j > > ava:2813) > >>> at er.extensions.eof.ERXEC.objectWillChange(ERXEC.java:769) > >>> at > >>> > > > > com.webobjects.eocontrol.EOObserverCenter.notifyObserversObjectWillChange(EOO > > bserverCenter.java:399) > >>> at > >>> > com.webobjects.eocontrol.EOCustomObject.willChange(EOCustomObject.java:333) > >>> at > >>> > > > > com.webobjects.eocontrol._EOMutableKnownKeyDictionary$Initializer$_GenericRec > > ordBinding.setValueInObject(_EOMutableKnownKeyDictionary.java:579) > >>> at > >>> > > > > com.webobjects.eocontrol.EOCustomObject.takeStoredValueForKey(EOCustomObject. > > java:1663) > >>> at > >>> > > > > er.extensions.eof.ERXGenericRecord.takeStoredValueForKey(ERXGenericRecord.jav > > a:1290) > >>> at com.bossing.wo.bids.db._Seo.setDescription(_Seo.java:52) > >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > >>> at > >>> > > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > >>> at > >>> > > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl. > > java:25) > >>> at java.lang.reflect.Method.invoke(Method.java:597) > >>> at > >>> > > > > com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1.setMethodValue(NSK > > eyValueCoding.java:643) > >>> at > >>> > > > > com.webobjects.foundation.NSKeyValueCoding$_MethodBinding.setValueInObject(NS > > KeyValueCoding.java:1150) > >>> at > >>> > > > > com.webobjects.eocontrol.EOCustomObject.takeValueForKey(EOCustomObject.java:1 > > 529) > >>> at > >>> > > > > er.extensions.eof.ERXGenericRecord.takeValueForKey(ERXGenericRecord.java:1282 > > ) > >>> at > >>> > > > > com.webobjects.foundation.NSKeyValueCoding$Utility.takeValueForKey(NSKeyValue > > Coding.java:469) > >>> at > >>> > > > > com.webobjects.foundation.NSValidation$DefaultImplementation.validateTakeValu > > eForKeyPath(NSValidation.java:679) > >>> at > >>> > > > > com.webobjects.eocontrol.EOCustomObject.validateTakeValueForKeyPath(EOCustomO > > bject.java:1335) > >>> at > >>> > > > > com.webobjects.foundation.NSValidation$Utility.validateTakeValueForKeyPath(NS > > Validation.java:502) > >>> at > >>> > > > > com.webobjects.foundation.NSValidation$DefaultImplementation.validateTakeValu > > eForKeyPath(NSValidation.java:687) > >>> at > >>> > > > > com.webobjects.eocontrol.EOCustomObject.validateTakeValueForKeyPath(EOCustomO > > bject.java:1335) > >>> at > >>> > > > > com.webobjects.foundation.NSValidation$Utility.validateTakeValueForKeyPath(NS > > Validation.java:502) > >>> > >>> Is my entity modeling correct? Any ideas how I can resolve this? > >>> > >>> Thanks, > >>> Amiel > >>> -- > >>> socket error: unable to connect to 127.0.0.1 > >>> _______________________________________________ > >>> 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/kenlists%40anderhome.com > > > > >>> > >>> This email sent to [email protected] > >>> > >> > >> > > > --- Disclaimer: > --------------------------------------------------------- This email and > contents is for use only by the intended recipient. If you are not the > individual or entity to whom it is addressed, you are hereby formally > notified that any use, copying or distribution of this email and > attachments, in whole or in part, is strictly prohibited. If you have > received this email in error, please notify the sender and delete the > message and attachment(s) from your system. Any views, opinions or > information, expressed or contained in this email, are those of the > sender and not necessarily reflect those of CEDES. To help protect our > environment, please avoid printing out this information unnecessarily. > -- socket error: unable to connect to 127.0.0.1
_______________________________________________ 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]
