0

I have several bridges in one Result class, which have a relationship with the same another Result class. For example in a Text class I have several bridges to the User class. So then, they will be named by default something like users and users_2s. I can remap those names with a rel_name_map option, but the question is whether there is any semantic behind those namings? How is it decided which one will be named users and which one will be named users_2s? Maybe if I create tables in another order on another machine the relationships will be named in another order and the users will become users_2s and vice versa? If I use rel_name_map and decide to rename them can I be sure that the order will be always preserved?

1 Answers1

0

Short answer: The database already has names for the bridges, and DBIx::Class will use those names. So you're safe from having them being renamed between runs so long as you aren't changing your database between runs.

If you look at your database with the right tools/commands you should see the names "users" and "user_2s" already associated with those bridges. Each "bridge" is a foreign key constraint, and as such has a name in your source database schema. The library function DBIx::Class::Schema::Loader::DBI::_table_fk_info calls the DBD handler's foreign_key_info method to get the bridges, and uses the given name.

If the handler doesn't return foreign-key names then it will generate a new name, using this format: __dcsld__$i, where $i is a number starting at 1. The numbering will only change if the in-database schema changes.

That dscld stands for DBIx::Class::Schema::Loader- and it doesn't match your bridge names, so your code must be getting those names from the database.

Yary
  • 325
  • 2
  • 7
  • Hi.Thanks for your reply. I guess I didn't formulate my question very clearly, so here I go again: both of my bridges have foreign key part with identical name 'user' and both point to the same table. I have a conflict here. So I program, that the default bridge name for first bridge suggested by schema loader should map to 'my_name', then the second bridge maps automatically to 'my_name_2s', which I say should map to 'his_name'. So my question is whether I can be sure, that 'my_name' will always map to the first suggested bridge and 'his_name' to the second on every machine where I create it? – Oleksii Andreiev Feb 11 '15 at 11:47