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

Fix/create reference with descriptor using inheritance #13

Merged
merged 3 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,13 @@ public T createReference(Boolean readOnly, boolean disableLazyLoad, Object id, P
}
}
try {
if (inheritInfo != null && !inheritInfo.isConcrete()) {
// we actually need to do a query because we don't know the type without the discriminator
// value, just select the id property and discriminator column (auto added)
DefaultOrmQuery<T> query = new DefaultOrmQuery<>(this, ebeanServer, ebeanServer.getExpressionFactory());
return query.select(getIdProperty().getName()).setId(id).findOne();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Der Code kommt jetzt doppelt vor


EntityBean eb = createEntityBean();
id = convertSetId(id, eb);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package io.ebeaninternal.server.deploy;

import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.bean.EntityBean;
import io.ebean.plugin.Property;
import org.junit.Test;
import org.tests.model.basic.Animal;
import org.tests.model.basic.AnimalShelter;
import org.tests.model.basic.Cat;
import org.tests.model.basic.Customer;
import org.tests.model.basic.Dog;
import org.tests.model.basic.Order;

import java.util.Collection;
Expand Down Expand Up @@ -46,6 +51,29 @@ public void createReference_when_disabledLazyLoad() {
Customer bean = customerDesc.createReference(Boolean.FALSE, true, 42, null);
assertThat(server().getBeanState(bean).isDisableLazyLoad()).isTrue();
}

@Test
public void createReference_with_inheritance() {
Cat cat = new Cat();
cat.setName("Puss");
Ebean.save(cat);

Dog dog = new Dog();
dog.setRegistrationNumber("DOGGIE");
Ebean.save(dog);

AnimalShelter shelter = new AnimalShelter();
shelter.setName("My Animal Shelter");
shelter.getAnimals().add(cat);
shelter.getAnimals().add(dog);

Ebean.save(shelter);

BeanDescriptor<Animal> animalDesc = spiEbeanServer().getBeanDescriptor(Animal.class);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das ist leider noch kein richtiger Test, da BeanDescriptor "ebeaninternal" ist. Hier solltest du einen Weg finden, der deine Query nachbildet.


Animal bean = animalDesc.createReference(Boolean.FALSE, false, dog.getId(), null);
assertThat(bean.getId()).isEqualTo(dog.getId());
}

@Test
public void allProperties() {
Expand Down