line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
OpenERP::OOM::Link::DBIC |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Class used to link OpenERP data with data in DBIC. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 PROPERTIES |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head2 dbic_schema |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
This is the DBIC Schema object. If you need a generic DBIC schema object |
15
|
|
|
|
|
|
|
this is normally the simplest way to access it. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
These methods are not normally called directly. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 create |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Returns the new ID of a row it creates in a table using DBIC. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $id = $link->create({ class => 'RSName' }, $object_data); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 retrieve |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This is equivalent to doing a find on a ResultSet. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $object = $link->retrieve({ class => 'RSName' }, $id); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 search |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This is equivalent to doing a search on a ResultSet and then returning a list |
36
|
|
|
|
|
|
|
of all the id fields. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @ids = $link->search({ class => 'RSName' }, $search, $options); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Copyright (C) 2011 OpusVL |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use 5.010; |
49
|
1
|
|
|
1
|
|
965
|
use Moose; |
|
1
|
|
|
|
|
5
|
|
50
|
1
|
|
|
1
|
|
5
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
51
|
1
|
|
|
1
|
|
5336
|
extends 'OpenERP::OOM::Link'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
338
|
|
52
|
|
|
|
|
|
|
with 'OpenERP::OOM::DynamicUtils'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'dbic_schema' => ( |
55
|
|
|
|
|
|
|
is => 'ro', |
56
|
|
|
|
|
|
|
lazy => 1, |
57
|
|
|
|
|
|
|
builder => '_build_dbic_schema', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
0
|
|
|
$self->ensure_class_loaded($self->config->{schema_class}); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return $self->config->{schema_class}->connect(@{$self->config->{connect_info}}); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my ($self, $args, $data) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
try { |
73
|
0
|
|
|
0
|
1
|
|
my $object = $self->dbic_schema->resultset($args->{class})->create($data); |
74
|
|
|
|
|
|
|
### Created linked object with ID $object->id |
75
|
|
|
|
|
|
|
return $object->id; |
76
|
0
|
|
|
0
|
|
|
} catch { |
77
|
|
|
|
|
|
|
die "Could not create linked object: $_"; |
78
|
0
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
0
|
|
|
|
81
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my ($self, $args, $id) = @_; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
if (my $object = $self->dbic_schema->resultset($args->{class})->find($id)) { |
87
|
|
|
|
|
|
|
return $object; |
88
|
0
|
|
|
0
|
1
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
0
|
0
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my ($self, $args, $search, $options) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# FIXME - Foreign primary key column is hard-coded to "id" |
97
|
|
|
|
|
|
|
return map {$_->id} $self->dbic_schema->resultset($args->{class})->search($search, $options)->all; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
0
|
1
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
102
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |