如何使用 Castle ActiveRecord 将表记录映射到任何类型

发布于 2024-09-06 05:49:47 字数 200 浏览 1 评论 0原文

我知道可以创建 Any 关系,其中相关记录可以是任何类型。

有没有办法告诉 ActiveRecord 表中的记录属于许多不同的类型,即使没有关系?例如,我有一个表,其中有一个字符串字段,用于存储表中每条记录的类型。我希望 ActiveRecord 能够识别每个记录的类型,并随后在查询该表时实例化正确的类型。

谁能说这是否可能?

I know it's possible to create Any relationships where the related record could be of any type.

Is there a way to tell the ActiveRecord the records in a table belong to many different types even when there is no relationships? For example I have a table in which there is a string field that stores the type of each record in table. I'd like ActiveRecord to recognize the type of each record and subsequently instantiate the correct type when querying that table.

Can anyone say if that's possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在看孤独的风景 2024-09-13 05:49:47

有三种方法可以做到这一点。每种方法的设计都适合以下三种情况:

单表继承 使用带有鉴别器列的单个表来确定每行包含哪种类型。

类表继承涉及为每个类使用不同的表,其中“基”表定义主键,而其他表“继承”它。

具体表继承是映射类层次结构的第三种方法,每个具体类都有自己的数据库表。

http://www.castleproject.org/activerecord/documentation/v1rc1/用户指南/typehierarchy.html

There are three ways of doing this. Each method is design to suit each of these three situations:

Single Table Inheritance uses a single table with a discriminator column to determine which type each row contains.

Class Table Inheritance involves using different tables for each class where the "base" table defined the primary key, and the others "inherit" it.

Concrete Table Inheritance is a third way to map a class hierarchy, each concrete class has its own database table.

http://www.castleproject.org/activerecord/documentation/v1rc1/usersguide/typehierarchy.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文