Question

I have a couple of tables like:

  • user
  • user_address -> with fk to users

And I'm generating my dbic schema using dbicdump. This creates the following relationship in User.pm:

__PACKAGE__->has_many( 
  "user_addresses", 
  "World::DBIC::Result::UserAddress", 
  { "foreign.user_id" => "self.id" }, 
  { cascade_copy => 0, cascade_delete => 0 },
);

Is it possible to change the name of the relationship to something like "addresses"? How? (I meant without changing the code before # DO NOT MODIFY THIS OR ANYTHING ABOVE!)

If not, is there any way to make an alias to the relationship?

Was it helpful?

Solution

Have a look at rel_name_map in DBIx::Class::Schema::Loader::Base. You should be able to do something like this when you create your schema:

my %args = ( 
    use_moose      => 1,
    use_namespaces => 1,
    rel_name_map   => { user_addresses => 'addresses' },
    # more args here...
);

make_schema_at( 'My::Schema', \%args, [ $connect_arg ... ] );

The rel_name_map is the important one, but I've added a few more lines for context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top