Why doesn't DBIx :: Class create many, many, many accessors?

While creating a schema from a database , many-to-many relationships between tables are not created.

Is this a major issue?

Is it possible to detect from the table structure that there are many-to-many relationships and automatically generate the appropriate code in the schema classes?

+4
source share
2 answers

The problem with developing such code is that many tables that contain multiple links are not many-to-many tables and have multiple links for other reasons. For example, I will create a diagram for some fictitious application in which something can be considered as a table of many to many, if it is not.

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, category references category(id), sub_category references sub_category(id), ... ); 

Something can be created this way for ease of use, without having to do multiple table joins in a database on a website, especially when considering speed. It would be difficult if the code snippet finally said “it's not so much,” while the developer should be able to easily understand it and add the many_to_many line under the checksum.

I believe that the DBIX :: Class schema provides a good starting point and a bit more, especially when working with automatic numbering in non-MySQL databases, by the way. I often need to modify the above “Do not modify above this line” (although many of them can obviously go below this checksum, of course.

+2
source

This is indeed a somewhat fundamental problem - many_to_many is a “bridge of connections”, not a “relationship”. The documentation explains that "the difference between a bridge and a relation is that the bridge cannot be used to join tables into a search, its component relationships should be used instead."

On the other hand, this means that if real relationships are correctly detected, it should be easy to add many-to-many relationships automatically: first, find tables that have two or more has_many relationships. Then, for each pair of such relationships, create a many-to-many relationship bridge. (Of course, you can hope that DBIx :: Class does this on its own.)

+5
source

Source: https://habr.com/ru/post/1345899/


All Articles