1 package DBIx::Class::TableInstance;
6 use base qw/DBIx::Class/;
7 use DBIx::Class::Table;
9 __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do anything yet!
11 __PACKAGE__->mk_classdata('_resultset_class' => 'DBIx::Class::ResultSet');
13 sub iterator_class { shift->table->resultset_class(@_) }
14 sub resultset_class { shift->table->resultset_class(@_) }
15 sub _table_name { shift->table->name }
19 DBIx::Class::TableInstance - provides a classdata table object and method proxies
23 __PACKAGE__->table('foo');
24 __PACKAGE__->add_columns(qw/id bar baz/);
25 __PACKAGE__->set_primary_key('id');
31 sub _mk_column_accessors {
32 my ($class, @cols) = @_;
33 $class->mk_group_accessors('column' => @cols);
38 __PACKAGE__->add_columns(qw/col1 col2 col3/);
40 Adds columns to the current class and creates accessors for them.
45 my ($class, @cols) = @_;
46 $class->table->add_columns(@cols);
47 $class->_mk_column_accessors(@cols);
50 sub resultset_instance {
52 $class->table->storage($class->storage);
53 $class->next::method($class->table->resultset);
57 return shift->table->columns;
62 __PACKAGE__->table('tbl_name');
64 Gets or sets the table name.
69 my ($class, $table) = @_;
70 die "$class->table called and no table instance set yet" unless $table;
72 $table = DBIx::Class::Table->new(
75 result_class => $class,
76 #storage => $class->storage,
79 $class->mk_classdata('table' => $table);
84 $class->find_or_create({ key => $val, ... });
86 Searches for a record matching the search condition; if it doesn't find one,
87 creates one and returns that instead.
93 my $hash = ref $_[0] eq "HASH" ? shift: {@_};
94 my $exists = $class->find($hash);
95 return defined($exists) ? $exists : $class->create($hash);
100 if ($obj->has_column($col)) { ... }
102 Returns 1 if the class has a column of this name, 0 otherwise.
107 my ($self, $column) = @_;
108 return $self->table->has_column($column);
113 my $info = $obj->column_info($col);
115 Returns the column metadata hashref for a column.
120 my ($self, $column) = @_;
121 return $self->table->column_info($column);
126 my @column_names = $obj->columns;
131 return shift->table->columns(@_);
138 Matt S. Trout <mst@shadowcatsystems.co.uk>
142 You may distribute this code under the same terms as Perl itself.