Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: DBIx::Class : stop changing table, column, relationship names

by NERDVANA (Deacon)
on Mar 01, 2023 at 09:57 UTC ( [id://11150660]=note: print w/replies, xml ) Need Help??


in reply to Re^2: DBIx::Class : stop changing table, column, relationship names
in thread DBIx::Class : stop changing table, column, relationship names

So you really just want the relationship name to be exactly the name of the table it links to? I think that can be done with

rel_name_map => sub { $_[0]{remote_moniker} }

To clarify some of your earlier questions, the reason that the moniker options were not having the desired effect is that they only affect the class name itself. They are assuming that most people have lowercase table names that might be plural and they assume that the average person wants to convert those to camel-case perl package names that are singular. They never considered that someone might want camel-case relationship names.

The reason why most people don't want camel-case relationship names or attribute names is that Perl's naming convention serves an important purpose. There is a namespace clash between a package name A::B and a fully qualified method name A::b and as soon as you start using uppercase method names, you can run into messy name conflicts. You can see this in the documentation of Type::Tiny (or Types::Standard, I forget where exactly) where the author recommends that everyone always call constructors as "A::B"->new instead of  A::B->new because the latter will break if there is a type named "B" imported into the namespace of package "A". Well, the real problem is that Type::Tiny encouraged people to import a bunch of symbols that start with a capital letter and have a high probability of conflicting with a package deeper in the hierarchy, and that those symbols remain in the package if you don't use namespace::clean; and then confuse perl's heuristics about whether you are referring to a package or calling a function. For DBIC relations it probably doesn't matter, because nobody is likely to want to define classes within the namespace of a Result class.

Replies are listed 'Best First'.
Re^4: DBIx::Class : stop changing table, column, relationship names
by bliako (Monsignor) on Mar 03, 2023 at 08:39 UTC

    Thank you NERDVANA. Your advice produced the result I wanted.

    If the schema is mine, then tablenames are all lowercase. Having a relationship name same as the table name (as I wanted) simplifies things for me given that there is only 1 relationship to the external table. If more relationships exist to the same table, then it produces the same relationship name for all, which is a very bad side-effect. So, being an eternal DBIx::Class (and SQL) newbie perhaps I should just stick to the defaults.

    Thanks, bliako

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11150660]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2024-04-16 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found