preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

bug: foreign keys use wrong table name #84

Closed mario-minati closed 4 years ago

mario-minati commented 4 years ago

In Yancy::Backend::Dbic are two differend approached to get the name of the source during read_schema.

The column property export uses:

        my $result_class = $source->result_class;
        # ; say "Adding class: $result_class ($table)";
        $classes{ $result_class } = $source;

The foreign key export uses:

my $self_table = $source->name;

and

my $foreign_table = $classes{ $foreign_class }->name;

According to the DBIx::Class doc the name method not allways delivers the correct value, instead the source_name method delvers the desired value.

Without that fix we get the schema with camel cased and snake cased table name mixed:

'office_employee' => {
                        'properties' => {}
                      },
'OfficeEmployee' => {
                       'properties' => {
                                         'email' => {
                                                      'type' => 'string',
                                                      'x-order' => 6
                                                    },
                                         'firstname' => {
                                                          'type' => 'string',
                                                          'x-order' => 3
                                                        },
                                         'lastname' => {
                                                         'type' => 'string',
                                                         'x-order' => 4
                                                       },
                                         'archived' => {
                                                         'type' => 'integer',
                                                         'x-order' => 7
                                                       },
                                         'title' => {
                                                      'type' => 'string',
                                                      'x-order' => 2
                                                    },
                                         'id' => {
                                                   'x-order' => 1,
                                                   'readOnly' => 1,
                                                   'type' => 'integer'
                                                 },
                                         'short' => {
                                                      'x-order' => 5,
                                                      'type' => 'string'
                                                    }
                                       },
                       'type' => 'object',
                       'required' => [
                                       'title',
                                       'firstname',
                                       'lastname',
                                       'short',
                                       'email',
                                       'archived'
                                     ]
                     },
preaction commented 4 years ago

Ah, looks like this only worked in my tests because all my DBIC result classes are lower-case and a single word (so that the names are the same as the other database tests). Thanks for the detailed report!