Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello Monks! This is surely clearly written somewhere, but I haven't been able to figure out.

I have this example setup:

Table PROJECT id (primary key for the table) ... Table ACCOUNT id (primary key for the table) project_id (reference to PROJECT.id) ... Table QUOTA id (primary key for the table) account_id (reference to ACCOUNT.id) ...

Using belongs_to it's easy to setup quick accessors and SQL magic like this:

Quota->belongs_to(account => 'Account'); Account->belongs_to(project => 'Project');

... which in turn make it easy to get the one project induced by a quota, like this:

my $project_from_quota = $quota->account()->project();

It's also easy to setup a convenience method, of course:

package Quota; sub project { return shift->account()->project() } #... my $project_from_quota = $quota->project();

I have the feeling that this is a bit hackish though, as it does not provide hints for SQL optimizations (like being able to easily prefetch the project when fetching the quota).

Is there any quick way to add that project accessor that also eases the SQL generator life, e.g. for prefetching stuff? Or should I rely upon the convenience method written above, and then put a bit more effort for using prefetch correctly?

I was thinking about has_one but that seems to be confined to direct relationships between two tables, while here I have the ACCOUNT table providing a bridge (that is anyway NOT inducing a many_to_many, as there is only ONE account for a quota, and ONE project for an account, hence ONE project for a quota).

Thanks for any hint!

perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?

In reply to DBIx::Class two (or multiple) level has_one by polettix

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (1)
    As of 2024-07-22 02:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.