Re: how does EOs are compared?
Re: how does EOs are compared?
- Subject: Re: how does EOs are compared?
- From: Ricardo Strausz <email@hidden>
- Date: Fri, 5 Sep 2003 18:33:17 -0500
Gracias Art!
On viernes, sept 5, 2003, at 17:32 America/Mexico_City, Art Isbell
wrote:
>> The code below, inserts ALL of the selected objects; it is failing to
>> determine if an object was inserted. Since I am using NSSets to try to
>> avoid duplicity, I am comparing with isEqual:
>> It does not works...
>
> isEqual: likely maps to equals() on the Java side.
> EOCustomObject.equals() is documentated to compare object handles
> (i.e., pointer addresses, EO1 == EO2) rather than EO contents.
>
> If you extracted dictionaries of the same attributes from inserted
> and source EOs and compared these dictionaries, then I think this
> would work.
>
> Aloha,
> Art
>
You are a genious... now it works!
(below the finial code)
Dino
http://homepage.mac.com/strausz
- (IBAction)add:(id)sender
{
NSArray* source = [dgDetallesP selectedObjects];
NSEnumerator* enSource = [source objectEnumerator];
EOGenericRecord* eo = nil;
NSMutableArray* cocoKeys = [NSMutableArray array];
[cocoKeys addObject:@"cantidad"];
[cocoKeys addObject:@"descripcion"];
id util = [[NSClassFromString(@"Util") new] autorelease]; // to do
the Java job
id keys = [util arrayWithArray:cocoKeys]; // this is a
WOMutableArray with the apropiate keys
NSMutableSet* inserted = [NSMutableSet set];
id arDet = [dgDetallesF allObjects];
NSEnumerator* enDet = [arDet objectEnumerator];
EOGenericRecord* eod = nil;
while([enDet hasMoreElements]){
eod = [enDet nextElement];
[inserted addObject:[eod valuesForKeys:keys]];
}
while([enSource hasMoreElements]){
eo = [enSource nextElement];
NSDictionary* nsd = [eo valuesForKeys:keys];
if(![inserted containsObject:nsd]){ // ... I do not want to
duplicate EOs !!!!!
EOGenericRecord* neo = [[NSClassFromString(@"BADetInvoice")
new] autorelease]; // a new EO to be inserted...
[neo takeValuesFromDictionary:nsd]; // ... which takes
values from another existing EO (in other entity), but...
[ec insertObject:neo];
[dgDetallesF insertObjectAtIndex:neo :0];
[dgDetallesF redisplay];
}
}
}
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.