Created
December 27, 2009 23:11
-
-
Save preaction/264439 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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