FIX: DbForeignkey with noConstraint and NotNull produces incorrect join type - Add forceLeftJoin option#2759
Conversation
It isn't clear to me why you expect this to be a LEFT JOIN. That is, my expectation is for It seems that there is some expectation that it should be a LEFT JOIN to allow for invalid values? |
|
Hello Rob, I want to explain you our use case: We want to import "stock orders" - All orders have an ISIN - stock value and amount and some other mandatory informations. So we have a "orders" and an "isin" object class Orders {
@Id
private UUID id;
@ManyToOne(optional = false)
@DbForeignKey(noConstraint = true)
private Isin isin;
...
}
// contains detail informations like company name, country and so on
class Isin {
@Id
@Size(max=12)
private String id;
}Which should produce the followin "order" table:
When we import the "Orders", we only create reference-Isin-beans to get the correct ISIN inserted in the order. On the one side, the ISIN in the "orders" must be "not null". It is not possible, to have an order without an ISIN. I understand the argument, that So how can we achieve to get a left-join here? Idea 2: @rbygrave What do you think?
Cheers |
|
The default join type ebean will use is based on cardinality + optionality. For the *ToOne case it then just comes down to optionality - which means in this case it's all down to whether the foreign key column is nullable. Also note that this is the default join type and LEFT JOIN needs to "cascade" to any subsequent "sub path/sub tree". What that means is that INNER JOIN get automatically converted to LEFT JOIN if a higher part of the path is LEFT JOIN. Using a
So I think we should go with Idea 1. Idea 1:@DbForeignKey(noConstraint = true) - Means the constraint is not enforced via the DB. Only affects DDL. I am wondering about the naming. If |
|
+1 for edit: sry, I misunderstand your last sentence. The more I think, the better I like https://www.reddit.com/r/ProgrammerHumor/comments/vs5jb2/naming_things/ ;) |
|
Ha ha, happy to go with |
|
@AlexWagner we need to review this. I've adjusted/reverted the forceLeftJoin option, as this is the code we have in production since ~1 year |
…roduces incorrect join type
|
Closing as resolved by #2759 |
The Combination of @NotNull and @DbForeignKey(noConstraint = true) produces the wrong join type in queries.
use case:
We import relations between datasets and we only get the primary key of those in this relation.
It is not sure if we get those other datasets per imports, but we want to know if there is a relation.
Fix is suggested in PR