有没有ORM支持组合w / o连接 [英] Is there an ORM that supports composition w/o Joins

查看:126
本文介绍了有没有ORM支持组合w / o连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:将标题从继承更改为合成。左侧的问题不变。

EDIT: Changed title from "inheritance" to "composition". Left body of question unchanged.

如果有一个支持继承的ORM工具,请创建要连接的单独表格,我很好奇。

I'm curious if there is an ORM tool that supports inheritance w/o creating separate tables that have to be joined.

简单的例子。假设一张客户的表格,一个帐单地址和一个供应商的表格,并附有一个汇款地址。保持简单,每个地址都有一个地址,而不是每个地址的子表。

Simple example. Assume a table of customers, with a Bill-to address, and a table of vendors, with a remit-to address. Keep it simple and assume one address each, not a child table of addresses for each.

这些地址将具有一些共同的值:地址1,地址2,城市,州/省,邮政编码。所以我们假设我有一个类addressBlock,我希望客户和供应商继承这个类,也可能来自其他类。但是我不想要单独的表必须加入,我想分别在客户和供应商表中列。

These addresses will have a handful of values in common: address 1, address 2, city, state/province, postal code. So let's say I'd have a class "addressBlock" and I want the customers and vendors to inherit from this class, and possibly from other classes. But I do not want separate tables that have to be joined, I want the columns in the customer and vendor tables respectively.

是否有ORM支持这一点?

Is there an ORM that supports this?

我在StackOverflow上找到的可能是同一个问题的最接近的问题是链接到下面,但是我不太清楚OP是否要求我在问什么他似乎正在询问上述继承,正是因为会有多个表。我正在寻找可以使用生成多个表的继承的情况。

The closest question I have found on StackOverflow that might be the same question is linked below, but I can't quite figure if the OP is asking what I am asking. He seems to be asking about foregoing inheritance precisely because there will be multiple tables. I'm looking for the case where you can use inheritance w/o generating the multiple tables.

使用Django的ORM的模型继承方法

推荐答案

JPA(Java Persistence API,由Hibernate,EclipseLink等人实现)支持:您可以定义一个地址POJO,将其标记为可嵌入,并具有两个实体(客户和供应商),每个实体的每个地址类型为Address(标记为嵌入)。客户地址的字段将映射到客户表中的列,供应商地址的字段将映射到供应商表中的列。

JPA (Java Persistence API, implemented by Hibernate, EclipseLink and others) supports this : You would define an Address POJO, mark it as "embeddable", and have two entities (Customer and Vendor) having each a field of type Address (marked as "embedded"). The fields of the customer address would be mapped to columns in the Customer table, and the fields of the vendor address would be mapped to columns in the Vendor table.

请注意这里没有遗产。继承是针对 is-a 关系。供应商不是地址,客户也不是地址。但是,由于供应商具有地址,客户具有地址,因此有组合。

Note that there's no inheritance here. Inheritance is for is-a relationships. A vendor is not an address, and a customer is not an address either. There is composition, though, because a vendor has an address, and a customer has an address.

这篇关于有没有ORM支持组合w / o连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆