- fix recent belongs_to changes
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSourceProxy / Table.pm
CommitLineData
80c90f5d 1package DBIx::Class::ResultSourceProxy::Table;
cda04c3a 2
3use strict;
4use warnings;
5
80c90f5d 6use base qw/DBIx::Class::ResultSourceProxy/;
25bb283d 7use DBIx::Class::ResultSource::Table;
cda04c3a 8
9__PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
10
25bb283d 11__PACKAGE__->mk_classdata('table_class' => 'DBIx::Class::ResultSource::Table');
cda04c3a 12
cda04c3a 13=head1 NAME
14
80c90f5d 15DBIx::Class::ResultSourceProxy::Table - provides a classdata table object and method proxies
cda04c3a 16
17=head1 SYNOPSIS
18
19 __PACKAGE__->table('foo');
20 __PACKAGE__->add_columns(qw/id bar baz/);
21 __PACKAGE__->set_primary_key('id');
22
23=head1 METHODS
24
cda04c3a 25=head2 add_columns
26
27 __PACKAGE__->add_columns(qw/col1 col2 col3/);
28
29Adds columns to the current class and creates accessors for them.
30
31=cut
32
cda04c3a 33=head2 table
34
35 __PACKAGE__->table('tbl_name');
36
37Gets or sets the table name.
38
39=cut
40
41sub table {
42 my ($class, $table) = @_;
b98e75f6 43 return $class->result_source_instance->name unless $table;
cda04c3a 44 unless (ref $table) {
f6858c33 45 $table = $class->table_class->new(
cda04c3a 46 {
47 name => $table,
48 result_class => $class,
cda04c3a 49 });
b98e75f6 50 if ($class->can('result_source_instance')) {
51 $table->{_columns} = { %{$class->result_source_instance->{_columns}||{}} };
20518cb4 52 $table->{_ordered_columns} =
53 [ @{$class->result_source_instance->{_ordered_columns}||[]} ];
ec77fadc 54 }
cda04c3a 55 }
b98e75f6 56 $class->mk_classdata('result_source_instance' => $table);
7fb16f1a 57 if ($class->can('schema_instance')) {
58 $class =~ m/([^:]+)$/;
59 $class->schema_instance->register_class($class, $class);
60 }
cda04c3a 61}
62
cda04c3a 63=head2 has_column
64
65 if ($obj->has_column($col)) { ... }
66
67Returns 1 if the class has a column of this name, 0 otherwise.
68
69=cut
70
cda04c3a 71=head2 column_info
72
73 my $info = $obj->column_info($col);
74
75Returns the column metadata hashref for a column.
76
77=cut
78
d7156e50 79=head2 columns
80
cda04c3a 81 my @column_names = $obj->columns;
82
83=cut
84
cda04c3a 851;
86
87=head1 AUTHORS
88
89Matt S. Trout <mst@shadowcatsystems.co.uk>
90
91=head1 LICENSE
92
93You may distribute this code under the same terms as Perl itself.
94
95=cut
96