解决方法
开发此类代码的问题在于,包含多个引用的许多表不是多对多表,并且由于其他原因而具有多个引用.例如,我将构建一个虚构应用程序的架构,其中某些东西可以被视为多对多表,而不是.
create table category ( id primary key,... ); create table sub_category ( id primary key,category references category(id),... ); /* EDIT: This is the table that could be regarded as many_to_many by an automated system */ create table product ( id primary key,sub_category references sub_category(id),... );
可以通过这种方式构建一些易于使用的东西,而无需在网站上的数据库中进行多个表连接,尤其是在考虑速度时.一段代码很难明确地说’这不是一个多少’的情况,而开发人员应该能够轻松搞清楚,并添加校验和下面的many_to_many行.
我认为DBIX :: Class模式输出一个很好的起点,而且更多,尤其是在非MysqL数据库中使用自动编号时.我经常需要修改上面的“不要在这行之上修改”的东西(当然,many_to_many显然可以低于那个校验和).