Interchange6-Schema

 view release on metacpan or  search on metacpan

lib/Interchange6/Schema/Result/Zone.pm  view on Meta::CPAN


=head1 ACCESSORS

=head2 zones_id

Primary Key.

=cut

primary_column zones_id => {
    data_type         => "integer",
    is_auto_increment => 1,
    sequence          => "zones_id_seq"
};

=head2 zone

For example for storing the UPS/USPS zone code or a simple name for the zone.

Unique constraint.

=cut

unique_column zone => { data_type => "varchar", size => 255 };

=head2 created

Date and time when this record was created returned as L<DateTime> object.
Value is auto-set on insert.

=cut

column created => { data_type => "datetime", set_on_create => 1 };

=head2 last_modified

Date and time when this record was last modified returned as L<DateTime> object.
Value is auto-set on insert and update.

=cut

column last_modified => {
    data_type     => "datetime",
    set_on_create => 1,
    set_on_update => 1,
};

=head1 RELATIONS

=head2 zone_countries

Type: has_many

Related object: L<Interchange6::Schema::Result::ZoneCountry>

=cut

has_many
  zone_countries => "Interchange6::Schema::Result::ZoneCountry",
  "zones_id",
  { cascade_copy => 0, cascade_delete => 0 };

=head2 countries

Type: many_to_many

Accessor to related country results ordered by name.

=cut

many_to_many
  countries => "zone_countries",
  "country",
  { order_by => 'country.name' };

=head2 zone_states

Type: has_many

Related object: L<Interchange6::Schema::Result::ZoneState>

=cut

has_many
  zone_states => "Interchange6::Schema::Result::ZoneState",
  "zones_id",
  { cascade_copy => 0, cascade_delete => 0 };

=head2 states

Type: many_to_many

Accessor to related state results ordered by name.

=cut

many_to_many
  states => "zone_states",
  "state", { order_by => 'state.name' };

=head2 shipment_destinations

C<has_many> relationship with
L<Interchange6::Schema::Result::ShipmentDestination>

=cut

has_many
  shipment_destinations => "Interchange6::Schema::Result::ShipmentDestination",
  "zones_id";

=head2 shipment_methods

C<many_to_many> relationship to shipment_method. Currently it ignores
the C<active> field in shipment_destinations.

=cut

many_to_many shipment_methods => "shipment_destinations", "shipment_method";

=head1 METHODS

=head2 new

Overloaded method. We allow a form of multi-create here so you can do something like:

    $schema->resultset('Zone')->create({
        zone      => 'some states of the USA',
        countries => [ 'US' ],
        states    => [ 'CA', 'PA' ],
    });

If there is only a single country or state the value can be a scalar instead of a hashref.

=cut

sub new {
    my ( $class, $attrs ) = @_;

    my ( $countries, $states, $new );

    if ( $attrs->{countries} ) {
        if ( ref( $attrs->{countries} ) eq 'ARRAY' ) {
            push @$countries, @{ $attrs->{countries} };
        }
        else {
            push @$countries, $attrs->{countries};



( run in 0.645 second using v1.01-cache-2.11-cpan-39bf76dae61 )