Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes/relationship naming #81

Merged
merged 7 commits into from Jun 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/Interchange6/Schema/Base/Attribute.pm
Expand Up @@ -54,10 +54,10 @@ sub add_attribute {
my ($attribute, $attribute_value) = $self->find_or_create_attribute($attr, $attr_value);

# create base_attribute object
my $base_attribute = $self->find_or_create_related($base . 'Attribute',
my $base_attribute = $self->find_or_create_related(lc($base) . '_attributes',
{attributes_id => $attribute->id});
# create base_attribute_value
$base_attribute->create_related($base . 'AttributeValue',
$base_attribute->create_related(lc($base) . '_attribute_values',
{attribute_values_id => $attribute_value->id});

return $self;
Expand Down Expand Up @@ -119,9 +119,9 @@ sub search_attributes {
my ($self) = @_;
my $base = $self->result_source->source_name;

my $base_attributes = $self->search_related($base . 'Attribute');
my $base_attributes = $self->search_related(lc($base) . '_attributes');

my $attributes = $base_attributes->search_related('Attribute');
my $attributes = $base_attributes->search_related('attribute');

return $attributes;
}
Expand Down Expand Up @@ -155,20 +155,20 @@ sub find_attribute_value {
}

# find records
my $base_attribute = $self->find_related($base . 'Attribute',
my $base_attribute = $self->find_related($lc_base . '_attributes',
{attributes_id => $attribute->id});

unless ($base_attribute) {
return;
}

my $base_attribute_value = $base_attribute->find_related($base .'AttributeValue',
my $base_attribute_value = $base_attribute->find_related($lc_base .'_attribute_values',
{$lc_base . '_attributes_id' => $base_attribute->id});
unless ($base_attribute_value) {
return;
}

my $attribute_value = $base_attribute_value->find_related('AttributeValue',
my $attribute_value = $base_attribute_value->find_related('attribute_value',
{lc($base) .'_attribute_values_id' => $base_attribute_value->id});
if ($object) {
return $attribute_value;
Expand Down Expand Up @@ -200,7 +200,7 @@ sub find_or_create_attribute {
my $attribute = $self->result_source->schema->resultset('Attribute')->find_or_create( %attr );

# create attribute_values
my $attribute_value = $attribute->find_or_create_related('AttributeValue', \%attr_value );
my $attribute_value = $attribute->find_or_create_related('attribute_values', \%attr_value );

return ($attribute, $attribute_value);
};
Expand All @@ -224,10 +224,10 @@ sub find_base_attribute_value {

my $lc_base = lc($base);

my $base_attribute = $self->find_related($base . 'Attribute',
my $base_attribute = $self->find_related($lc_base . '_attributes',
{attributes_id => $attribute->id});

my $base_attribute_value = $base_attribute->find_related($base . 'AttributeValue',
my $base_attribute_value = $base_attribute->find_related($lc_base . '_attribute_values',
{$lc_base . '_attributes_id' => $base_attribute->id});

return ($base_attribute, $base_attribute_value);
Expand Down
24 changes: 12 additions & 12 deletions lib/Interchange6/Schema/Populate/Zone.pm
Expand Up @@ -47,8 +47,8 @@ sub records {

push @zones,
{
zone => $country_name,
ZoneCountry => [ { country_iso_code => $country_code } ],
zone => $country_name,
zone_countries => [ { country_iso_code => $country_code } ],
};

# one zone per state
Expand All @@ -65,9 +65,9 @@ sub records {

push @zones,
{
zone => $zone,
ZoneCountry => [ { country_iso_code => $country_code } ],
ZoneState => [ { states_id => $state->{'states_id'} } ],
zone => $zone,
zone_countries => [ { country_iso_code => $country_code } ],
zone_states => [ { states_id => $state->{'states_id'} } ],
};
}
}
Expand All @@ -76,18 +76,18 @@ sub records {
# US lower 48 includes all 51 from US except for Alaska and Hawaii
push @zones,
{
zone => 'US lower 48',
ZoneCountry => [ { country_iso_code => 'US' } ],
ZoneState => [
zone => 'US lower 48',
zone_countries => [ { country_iso_code => 'US' } ],
zone_states => [
map { { 'states_id' => $states_by_country{US}{$_}->{'states_id'} } }
grep { !/(AK|HI)/ } keys %{ $states_by_country{US} }
],
};

# EU member states
push @zones, {
zone => 'EU member states',
ZoneCountry => [
zone => 'EU member states',
zone_countries => [
map { { 'country_iso_code' => $_ } }
qw ( BE BG CZ DK DE EE GR ES FR HR IE IT CY LV LT LU HU MT
NL AT PL PT RO SI SK FI SE GB )
Expand All @@ -96,8 +96,8 @@ sub records {

# EU VAT countries = EU + Isle of Man
push @zones, {
zone => 'EU VAT countries',
ZoneCountry => [
zone => 'EU VAT countries',
zone_countries => [
map { { 'country_iso_code' => $_ } }
qw ( BE BG CZ DK DE EE GR ES FR HR IE IT CY LV LT LU HU MT
NL AT PL PT RO SI SK FI SE GB IM )
Expand Down
33 changes: 12 additions & 21 deletions lib/Interchange6/Schema/Result/Address.pm
@@ -1,9 +1,6 @@
use utf8;
package Interchange6::Schema::Result::Address;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

Interchange6::Schema::Result::Address
Expand Down Expand Up @@ -189,7 +186,7 @@ __PACKAGE__->set_primary_key("addresses_id");

=head1 RELATIONS

=head2 OrderlinesShipping
=head2 orderlines_shipping

Type: has_many

Expand All @@ -198,13 +195,13 @@ Related object: L<Interchange6::Schema::Result::OrderlinesShipping>
=cut

__PACKAGE__->has_many(
"OrderlinesShipping",
"orderlines_shipping",
"Interchange6::Schema::Result::OrderlinesShipping",
{ "foreign.addresses_id" => "self.addresses_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 Order
=head2 orders

Type: has_many

Expand All @@ -213,13 +210,13 @@ Related object: L<Interchange6::Schema::Result::Order>
=cut

__PACKAGE__->has_many(
"Order",
"orders",
"Interchange6::Schema::Result::Order",
{ "foreign.billing_addresses_id" => "self.addresses_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 User
=head2 user

Type: belongs_to

Expand All @@ -228,13 +225,13 @@ Related object: L<Interchange6::Schema::Result::User>
=cut

__PACKAGE__->belongs_to(
"User",
"user",
"Interchange6::Schema::Result::User",
{ users_id => "users_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);

=head2 State
=head2 state

Type: belongs_to

Expand All @@ -243,13 +240,13 @@ Related object: L<Interchange6::Schema::Result::State>
=cut

__PACKAGE__->belongs_to(
"State",
"state",
"Interchange6::Schema::Result::State",
{ states_id => "states_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);

=head2 Country
=head2 country

Type: belongs_to

Expand All @@ -258,7 +255,7 @@ Related object: L<Interchange6::Schema::Result::Country>
=cut

__PACKAGE__->belongs_to(
"Country",
"country",
"Interchange6::Schema::Result::Country",
{ country_iso_code => "country_iso_code" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
Expand All @@ -268,16 +265,10 @@ __PACKAGE__->belongs_to(

Type: many_to_many

Composing rels: L</OrderlinesShipping> -> Orderline
Composing rels: L</orderlines_shipping> -> orderline

=cut

__PACKAGE__->many_to_many("orderlines", "OrderlinesShipping", "Orderline");


# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-11-08 09:38:12
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3sqnKWloErZti2AMvhkWfw

__PACKAGE__->many_to_many("orderlines", "orderlines_shipping", "orderline");

# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
12 changes: 6 additions & 6 deletions lib/Interchange6/Schema/Result/Attribute.pm
Expand Up @@ -101,7 +101,7 @@ __PACKAGE__->set_primary_key("attributes_id");

=head1 RELATIONS

=head2 AttributeValue
=head2 attribute_values

Type: has_many

Expand All @@ -110,13 +110,13 @@ Related object: L<Interchange6::Schema::Result::AttributeValue>
=cut

__PACKAGE__->has_many(
"AttributeValue",
"attribute_values",
"Interchange6::Schema::Result::AttributeValue",
{ "foreign.attributes_id" => "self.attributes_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 ProductAttribute
=head2 product_attributes

Type: has_many

Expand All @@ -125,13 +125,13 @@ Related object: L<Interchange6::Schema::Result::ProductAttribute>
=cut

__PACKAGE__->has_many(
"ProductAttribute",
"product_attributes",
"Interchange6::Schema::Result::ProductAttribute",
{ "foreign.attributes_id" => "self.attributes_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 NavigationAttribute
=head2 navigation_attributes

Type: has_many

Expand All @@ -140,7 +140,7 @@ Related object: L<Interchange6::Schema::Result::NavigationAttribute>
=cut

__PACKAGE__->has_many(
"NavigationAttribute",
"navigation_attributes",
"Interchange6::Schema::Result::NavigationAttribute",
{ "foreign.attributes_id" => "self.attributes_id" },
{ cascade_copy => 0, cascade_delete => 0 },
Expand Down
16 changes: 8 additions & 8 deletions lib/Interchange6/Schema/Result/AttributeValue.pm
Expand Up @@ -90,7 +90,7 @@ __PACKAGE__->set_primary_key("attribute_values_id");

=head1 RELATIONS

=head2 Attribute
=head2 attribute

Type: belongs_to

Expand All @@ -99,13 +99,13 @@ Related object: L<Interchange6::Schema::Result::Attribute>
=cut

__PACKAGE__->belongs_to(
"Attribute",
"attribute",
"Interchange6::Schema::Result::Attribute",
{ attributes_id => "attributes_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);

=head2 ProductAttributeValue
=head2 product_attribute_values

Type: has_many

Expand All @@ -114,13 +114,13 @@ Related object: L<Interchange6::Schema::Result::ProductAttributeValue>
=cut

__PACKAGE__->has_many(
"ProductAttributeValue",
"product_attribute_values",
"Interchange6::Schema::Result::ProductAttributeValue",
{ "foreign.attribute_values_id" => "self.attribute_values_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 UserAttributeValue
=head2 user_attribute_values

Type: has_many

Expand All @@ -129,13 +129,13 @@ Related object: L<Interchange6::Schema::Result::UserAttributeValue>
=cut

__PACKAGE__->has_many(
"UserAttributeValue",
"user_attribute_values",
"Interchange6::Schema::Result::UserAttributeValue",
{ "foreign.attribute_values_id" => "self.attribute_values_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

=head2 NavigationAttributeValue
=head2 navigation_attribute_values

Type: has_many

Expand All @@ -144,7 +144,7 @@ Related object: L<Interchange6::Schema::Result::NavigationAttributeValue>
=cut

__PACKAGE__->has_many(
"NavigationAttributeValue",
"navigation_attribute_values",
"Interchange6::Schema::Result::NavigationAttributeValue",
{ "foreign.attribute_values_id" => "self.attribute_values_id" },
{ cascade_copy => 0, cascade_delete => 0 },
Expand Down