TRAVAIL > DBIx-Class-Schema-Slave-0.02400 > DBIx::Class::Row::Slave

Download:
DBIx-Class-Schema-Slave-0.02400.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

DBIx::Class::Row::Slave - DBIx::Class::Row for slave (EXPERIMENTAL)

SYNOPSIS ^

  # In your MyApp::Schema::Artist
  # Don't forget load this component
  __PACKAGE__->load_components( qw/ Row::Slave Core / );

  # Somewhere in your code
  use MyApp::Schema;

  # Connecting your Schema
  my $schema = MyApp::Schema->connect( @info );

  # Retrieving from master
  my $master = $schema->resultset('Artist')->find( $id );

  # Retrieving from slave
  my $slave  = $schema->resultset('Artist::Slave')->find( $id );

  # Adding in master
  # Complete normally
  my $master = $schema->resultset('Artist')->create( { ... } );

  # Adding in slave
  # You got an error!
  # DBIx::Class::ResultSet::create(): Can't insert via result source "Artist::Slave". This is slave connection.
  my $slave = $schema->resultset('Artist::Slave')->create( { ... } );

  # Also you can neither update nor delete via slave result_sources.
  my $slave = $schema->resultset('Artist::Slave')->single( { name => 'QURULI' } );
  $slave->name('RADIOHEAD');

  # DBIx::Class::Row::Slave::update(): Can't update via result source "Artist::Slave". This is slave connection.
  $slave->update;

  # DBIx::Class::Row::Slave::delete(): Can't delete via result source "Artist::Slave". This is slave connection.
  $slave->delete;

See DBIx::Class::Row.

DESCRIPTION ^

DBIx::Class::Row::Slave is DBIx::Class::Row for slave. It provide no novel functions, but rather restrict some functions via slave result_sources. You can retrieve rows from either master or slave but you can neither add nor remove rows from slave.

METHODS ^

insert

Throw exception if called via slave result_sources.

update

Throw exception if called via slave result_sources.

delete

Throw exception if called via slave result_sourcess.

is_slave

Return Value: 1 or 0

This method returns 1 if the row is retrieved via slave result_source, otherwise returns 0.

  my $master = $schema->resultset('Artist')->find( $id );
  my $slave  = $schema->resultset('Artist::Slave')->find( $id );

  # Returns 0
  $master->is_slave;

  # Returns 1
  $slave->is_slave;

AUTHOR ^

travail travail@cabane.no-ip.org

COPYRIGHT ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

syntax highlighting: