After doing a bit more reading, I thought I could do this in a join by
passing $self->{self_resultsource}->pk a few resultsets down. However,
I now don't think this will work. I'm now thinking that maybe
DBIx::Class::ResultSet::WithMetaData might work if I get
$result_source->pk of 'page' and maybe
$url_rs->page_meta->find_or_create_related(); but idk how to pass the
pk into find_or_create_related().

Also, I cross posted to perlmonks and haven't gotten any farther there
either: http://www.perlmonks.org/?node_id=1028559

On Fri, Apr 12, 2013 at 4:26 PM, shawn wilson <ag4ve...@gmail.com> wrote:
> How do I maintain a circular reference? The relation part of the
> schema is below, but 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 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;

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to