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

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.

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

  • Should I use Class Table Inheritance? (so Booking and Refund extends some class which has only $id and $creation_time properties)
  • Should I use Single Table Inheritance? (so all Booking and Refund data is stored in one table)
  • Something else?

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.

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.

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