Skip to content

Instantly share code, notes, and snippets.

@preaction
Created December 27, 2009 23:11
Show Gist options
  • Save preaction/264439 to your computer and use it in GitHub Desktop.
Save preaction/264439 to your computer and use it in GitHub Desktop.
package WebGUIx::Asset::Data;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw{ VirtualColumns Core });
__PACKAGE__->table( "assetData" );
__PACKAGE__->add_virtual_columns( "session" );
package WebGUIx::Asset::RawContent;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw{ VirtualColumns Core });
__PACKAGE__->table( "RawContent" );
__PACKAGE__->add_virtual_columns( "session" );
__PACKAGE__->belongs_to(
'data' => 'WebGUIx::Asset::Data',
{
'foreign.assetId' => 'self.assetId',
'foreign.revisionDate' => 'self.revisionDate',
},
);
sub new {
my ( $class, $attr ) = @_;
my $session = $attr->{session};
$attr->{ userId } ||= $session->user->userId; # and other stuff from $session
my $self = $class->next::method( $attr );
$self->data->session( $session );
return $self;
}
package main;
my $session = WebGUI::Session->open();
my $asset = $schema->resultset('RawContent')->create({
session => $session,
});
$asset->session; # Exists
$asset->data->session; # Does not exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment