Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast EOCustomObject abstract #844

Closed
algodata44 opened this issue Nov 23, 2017 · 5 comments
Closed

Cast EOCustomObject abstract #844

algodata44 opened this issue Nov 23, 2017 · 5 comments
Assignees

Comments

@algodata44
Copy link

algodata44 commented Nov 23, 2017

Hi,

Help please.
I have an Entity Abstract named "EntityAbstract" and a subclass Entity named "EntitySub" where the qualifier is (type='entity-sub').
I have third Entity named "Relation" that has an relationship with "EntityAbstract".

I have a problem when :

EOEditingContext eo = ERXEC.newEditingContext();

Relation relation = Relation.fetchRelation(eo, Relation.ID.eq(id));
EntityAbstract entityAbstract = ERXEOControlUtilities.createAndInsertObject(eo, EntityAbstract.class);
entityAbstract.setRelationRelationship(relation);
entityAbstract.setType("entity-sub");
eo.saveChanges();

eo = ERXEC.newEditingContext();

Relation relationFetched = Relation.fetchRelation(eo, Relation.ID.eq(id));
System.err.println(relationFetched.entitySub()); // Print : <EntityAbstract pk:"...">

How to print <Entity pk:"..."> and not <EntityAbstract pk:"..."> ?

I don't want use the class "Entity" for ERXEOControlUtilities.createAndInsertObject

Do you have an idea?

I tested :

eo.invalidateAllObjects(); eo.parentObjectStore().invalidateAllObjects(); eo.rootObjectStore().invalidateAllObjects();

It does not work...

Thx

@spelletier
Copy link
Member

Hi,
You did not explained your functional needs so I can only comment the code.

By definition it is not possible to instantiate an abstract entity (or class). You can only create objects of real complete entities (classes).

I think there is a problem with your model or the way you want to use it.

I use Abstract entities in all my projects (single table flavour). They are really easy to use with Wonder because the framework takes care of adding the restricting qualifier automatically.

The only limit is you cannot change the type of an object (record) with EOF. An EntitySub will remains an EntitySub forever after it's creation.

Samuel

@algodata44
Copy link
Author

The only limit is you cannot change the type of an object (record) with EOF. An EntitySub will remains an EntitySub forever after it's creation.

It's true? there is no solution for that?

When I re-compile (after created the EntityAbstract) I have the good result :
Relation relationFetched = Relation.fetchRelation(eo, Relation.ID.eq(id)); System.err.println(relationFetched.entitySub()); // Print <EntitySub pk:"...">

Why? How to remove the object from cache? It's possible?

@spelletier
Copy link
Member

You should explain the problem you try to solve. Changing the class of an existing object make no sense and I do not know any langage that supports that. If you think you need to do that, you probably need to adjust your design. EOF is meant to be used with OO design, you works with objects and the framework manage the reads and writes to the Database.

Maybe ERXPartial would helps if the design cannot change. I never used them but my understanding is they work in a way similar to interfaces in Java. These allows to use an entity X objects as a partial object like a dynamic cast.

@paulhoadley paulhoadley self-assigned this Nov 23, 2017
@paulhoadley
Copy link
Contributor

This sounds like something that @algodata44 should take up on the mailing list. This isn't really a Wonder issue (in the GitHub sense).

While we're here, though:

Maybe ERXPartial would helps if the design cannot change. I never used them but my understanding is they work in a way similar to interfaces in Java.

Partial entities are a bit like single table inheritance, but using composition rather than object inheritance. They work great—we've been using them in production for years. If this would help the original poster, we can discuss over on the list.

@algodata44
Copy link
Author

Thx, ok I will write an email on the mailing list.
Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants