views:

477

answers:

1

I have a superentity called FObject with several subentities, say Foo1, Foo2, and Foo3. I have a number of tableviews that should show information about different collections of the subentities, so for example, one shows only Foo2s and Foo3s while another shows all of them.

How do I write a predicate to filter on the subentity type, given that I am fetching on FObject?

I tried "entity.name IN %@" and provided a list of entity names but that did not work.

Or should I just filter the returned results?

Or should I add an attribute that codes the type and use "type IN %@"?

A: 

If you have different table views to show instances of the various sub-entities, you presumably have NSArrayControllers for each table, correct? If that's the case, why not set the entity name for the array controller to the desired sub-entity's name?

This is the name used in the fetch request (where you specify the entity name to fetch). The predicate used in the fetch request is used to filter by attribute or relationship, not entity name.

Joshua Nozzi
That will give me one entity per table. I want a specific mix of entities in each table: not one, not all.
Steve Weller
Ah, I see. Since each fetch request must be for a specific entity name, you won't be able to filter this during the fetch. I would filter them in memory if they have to be separate entities. Alternatively, you could flatten things a bit and simply *not* have different entities (using a "type" attribute to allow filtering during the fetch). I think it's far better than having separate entity names *and* adding a type attribute.
Joshua Nozzi
I went with the adding an attribute solution. It works just fine. However I need to keep my entity hierarchy because there are many common attributes and relationships between the entity types as well as many differences. I'm mirroring an existing object-oriented system that's sending me data.
Steve Weller