Doctrine2存储不同对象的最佳方式是什么 - 显示在一个列表中

时间:2021-08-13 06:47:55

I have two kind of objects: Booking and Refund (they are completely different).
I'll need to show them in one list - sorted by creation time.
Also I'll have to do export to excel - so I'll need to generate list of millions rows.

我有两种对象:预订和退款(它们完全不同)。我需要在一个列表中显示它们 - 按创建时间排序。此外,我将不得不导出到Excel - 所以我需要生成数百万行的列表。

What is the best way to store them using Doctrine 2:

使用Doctrine 2存储它们的最佳方法是什么:

  • Should I use Class Table Inheritance? (so Booking and Refund extends some class which has only $id and $creation_time properties)
  • 我应该使用类表继承吗? (所以Booking和Refund扩展了一些只有$ id和$ creation_time属性的类)

  • Should I use Single Table Inheritance? (so all Booking and Refund data is stored in one table)
  • 我应该使用单表继承吗? (所以所有预订和退款数据都存储在一个表格中)

  • Something else?

1 个解决方案

#1


0  

There's no real difference between CTI and STI for the problem you've got. But your assumptions are kinda off. You should inherit objects if they have common points, but you say they're completely different - make sure they do share some points in a logical way.

对于你遇到的问题,CTI和STI之间没有真正的区别。但是你的假设有点不对劲。你应该继承对象,如果它们有共同点,但你说它们完全不同 - 确保它们以逻辑方式共享某些点。

Nonetheless doctrine inheritance has its downsides, make sure you understand them before you begin.

尽管如此,学说继承有其缺点,请确保在开始之前理解它们。

The other option is if it's a single query only consider an UNION. This way you can fetch things from two tables making them share same interface. Though you'll need to use native query.

另一种选择是,如果它是单个查询,则只考虑UNION。这样,您可以从两个表中获取内容,使它们共享相同的接口。虽然您需要使用本机查询。

SELECT id, price, whatever, 'booking' as type FROM booking 
UNION
SELECT id, price, whatever, 'refund' as type FROM refund 
ORDER BY created

#1


0  

There's no real difference between CTI and STI for the problem you've got. But your assumptions are kinda off. You should inherit objects if they have common points, but you say they're completely different - make sure they do share some points in a logical way.

对于你遇到的问题,CTI和STI之间没有真正的区别。但是你的假设有点不对劲。你应该继承对象,如果它们有共同点,但你说它们完全不同 - 确保它们以逻辑方式共享某些点。

Nonetheless doctrine inheritance has its downsides, make sure you understand them before you begin.

尽管如此,学说继承有其缺点,请确保在开始之前理解它们。

The other option is if it's a single query only consider an UNION. This way you can fetch things from two tables making them share same interface. Though you'll need to use native query.

另一种选择是,如果它是单个查询,则只考虑UNION。这样,您可以从两个表中获取内容,使它们共享相同的接口。虽然您需要使用本机查询。

SELECT id, price, whatever, 'booking' as type FROM booking 
UNION
SELECT id, price, whatever, 'refund' as type FROM refund 
ORDER BY created