I'm not entirely sure what you're saying here. Schema::Loader reads the structure of your database to generate DBIC result classes, and it ignores the names of the foreign keys in your database and makes guesses about what the name of the relationship should be based on the column names involved. If you declare one of those naming conventions, it will generate the same names every time, but it has no idea what the relationship name "should" be.

If you have relationships defined in JSON, then why are you using Schema::Loader? You could just generate the DBIC result classes however you like. If you want to pick up the database column names, but define custom relationships, you can do that by putting the relationships below the auto-generated code, and Schema::Loader will preserve all that custom code while re-generating the column definitions.

There is one project where I wanted to retroactively use SchemaLoader, but other developers had already chosen all sorts of names for the relationships, and I needed to preserve that. I ended up writing a very long rel_name_map parameter in my script that runs Schema::Loader to override all its choices of relationship name. i.e.

rel_name_map => { Group => { reportnum => 'report', rpt_sections => 'sections', },
and so on for ~50 relationships or so. It was annoying and tedious, but let me choose all the specific names I needed to preserve. I don't recommend this really; since you have them in JSON already you could just tell Schema::Loader to ignore foreign keys and then inject the relationships into the generated code yourself with option filter_generated_code.

In reply to Re: DBIx::Class : stop changing table, column, relationship names by NERDVANA
in thread DBIx::Class : stop changing table, column, relationship names by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.