Knocking meekly on the gates the lowly monk creeps forward, hoping his brethren can help save his sanity.

We're learning about Class::DBI, and have mocked up some samples to see if it meets our needs. So far, it all seems excellent, but I've hit a snag I can't understand.

The issue seems to be some interaction between many to many relationships and overriding the standard accessor names. In the base class that derives from Class::DBI (which all our other classes then derive from), we have the following:

sub accessor_name { my ($_class, $_column) = @_; my $_accessor = $_column; $_accessor = ucfirst $_accessor; $_accessor = 'Get' . $_accessor; $_accessor =~ s/id$/Id/smx; return $_accessor; } sub mutator_name { my ($_class, $_column) = @_; my $_mutator = $_column; $_mutator = ucfirst $_mutator; $_mutator = 'Set' . $_mutator; $_mutator =~ s/id$/Id/smx; return $_mutator; }
This makes all accessors and mutators follow our standard naming convention. So far, so good, it works as expected.

Now we have a many to many relationship between classA and classB. This is done using a table tableClassAtoB. The problem comes when we do the following:

my $classBItr = $classA->classBs(); while ( my $b = $classBItr->next() ) { ... }
When the next() is executed, we get the error:
Can't locate object method "classB_id" via package "ClassAtoB" at /usr +/lib/site_perl/5.8.5/Class/DBI/Iterator.pm line 77.
Due to how we've overriden the accessor name, it's clear to me that the method classB_id doesn't exist. We've used the Class::DBI functionality to change it to ClassB_Id(). But apparently Class::DBI::Iterator does not know that.

What are we doing wrong? Do we need to subclass the Class::DBI::Iterator and create our own?

Thanks Monks!


In reply to Class::DBI::Iterator and overriding accessors by HuckinFappy

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.