ag4ve has asked for the wisdom of the Perl Monks concerning the following question:
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# Source__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;
# Data__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;
__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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBIC circular relationship
by NetWallah (Canon) on Apr 14, 2013 at 05:58 UTC | |
by ag4ve (Monk) on Apr 14, 2013 at 19:56 UTC | |
by NetWallah (Canon) on Apr 14, 2013 at 21:21 UTC |