I posted this a while ago on the DBIC list and haven't heard anything. How do I maintain a circular reference? The relation part of the schema is below, so I can do:

my $url_rs = $self->search({url => $url})->single; foreach my $text (@{$data->{$domain}{$url}}) { try { $schema->txn_do(sub { $url_rs->find_or_create_related('data', { text => $text, stamp => $eptime, source => { proxy => $info->{proxy}, ip => $info->{ip} // '0.0.0.0', }, }); }); } catch { print STDERR "[$text] $_\n"; die; }; } }

Where I can go from page and insert into 'data' and 'source'. But, how do I fill in the source_fk in the page table that I orriginate from?

# Page
__PACKAGE__->add_columns( 'page_pk', { data_type => 'integer', extra => { unsigned => 1 }, is_auto_increment => 1, is_nullable => 0, }, 'source_fk', { data_type => 'integer', extra => { unsigned => 1 }, is_foreign_key => 1, is_nullable => 1, }, ); __PACKAGE__->has_many( 'data', 'WebDat::Schema::Result::Data', { 'foreign.page_fk' => 'self.page_pk' }, { is_deferrable => 1 }, ); __PACKAGE__->belongs_to( 'source' => 'WebDat::Schema::Result::Source', { 'foreign.source_pk' => 'self.source_fk' }, { is_deferrable => 1 }, ); 1;
# Source
__PACKAGE__->add_columns( 'source_pk', { data_type => 'integer', extra => { unsigned => 1 }, is_auto_increment => 1, is_nullable => 0, }, ); __PACKAGE__->has_many( 'data', 'WebDat::Schema::Result::Data', { 'foreign.source_fk' => 'self.source_pk' }, { is_deferrable => 1 }, ); __PACKAGE__->has_many( 'page', 'WebDat::Schema::Result::Page', { 'foreign.source_fk' => 'self.source_pk' }, { is_deferrable => 1 }, ); 1;
# Data
__PACKAGE__->add_columns( 'data_pk', { data_type => 'integer', extra => { unsigned => 1 }, is_auto_increment => 1, is_nullable => 0, }, 'page_fk', { data_type => 'integer', extra => { unsigned => 1 }, is_foreign_key => 1, is_nullable => 0, }, 'source_fk', { data_type => 'integer', extra => { unsigned => 1 }, is_foreign_key => 1, is_nullable => 0, }, ); __PACKAGE__->belongs_to( 'page' => 'WebDat::Schema::Result::Page', { 'foreign.page_pk' => 'self.page_fk' }, { is_deferrable => 1 }, ); __PACKAGE__->belongs_to( 'source', 'WebDat::Schema::Result::Source', { 'foreign.source_pk' => 'self.source_fk' }, { is_deferrable => 1 }, ); 1;

In reply to DBIC circular relationship by ag4ve

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.