如何避免数据存储到页面 table

How to avoid data being stored to Page table

根据我的经验,如果在创建新 class 时未指定 $db,则该页面类型的所有数据都会进入 Page && SiteTree tables。

我个人觉得这种行为非常混乱和无组织,希望任何定义为自己的东西都有自己的东西 table。

有没有办法显式设置一个新的 class 来拥有和使用它自己的 table 而不管它是否有通过 $db 添加的任何额外字段?

Is there any way to explicitly set a new class to have and use its own table regardless if it does or doesn't have any additional fields added via $db?

没有

一旦 DataObjectSiteTree 只是其子类)包含一个 $db 静态,然后会创建一个同名的 table,其字段位于它包含您在 $db.

中定义的那些字段

对 "break SilverStripe" 以及它如何使用其 ORM 做任何不同的事情。如果您创建一个 DataList 并转储其 sql() 方法的输出,您将看到 Page 的查询已连接到 SiteTree table。这样做实际上是 tidier 因为您总是可以期望 TitleContent (等)字段位于 SiteTree table 以及您在 PagePage 子类中声明的任何自定义项,都在它们各自的 table(s).

$sql = SiteTree::get()->filter('ClassName', 'Page')->sql();
var_dump($sql);