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

fix: bug column name when sequelize model mapping attribute has field… #283

Conversation

Jekiwijaya
Copy link

@Jekiwijaya Jekiwijaya commented Jul 2, 2019

Fixing bug column name when sequelize model mapping attribute has field option

access the schema field columnName instead access directly through the fieldName.

Closed #282
Closed #273

Pull Request checklist:

  • Write an explicit title for the Pull Request
  • Write changes made in the CHANGELOG.md
  • Create automatic tests
  • Test manually the implemented changes
  • Review my own code (indentation, syntax, style, simplicity, readability)
  • Wonder if you can improve the existing code

… option

access the schema field columnName instead access directly through the fieldName.

Closed ForestAdmin#282
Closed ForestAdmin#273
CHANGELOG.md Outdated Show resolved Hide resolved
return `${schema.name}.${fieldName}`;
const schemaField = schema.fields.find(schemaField => schemaField.field === fieldName);
const columnName = schemaField ? schemaField.columnName : fieldName;
return `${schema.name}.${columnName}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could factorise this logic in a dedicated method.
It would improve the code maintenance and readability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there is already a method for this purpose in the existing code.

@@ -318,6 +319,24 @@ const HasManyDissociator = require('../src/services/has-many-dissociator');
});

describe('A simple Line Chart per day on an empty users table', () => {
it('should generate a valid SQL query when models mapped to another field', (done) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"when models mapped to another field" should actually be in a describe in my opinion:

describe('A simple Line Chart per day on an empty users table', () => {
  describe('with a group_by_date_field  field having a conventional name', () => {
    it('should generate a valid SQL query', (done) => {
      // TEST
    });
  });

  describe('with a group_by_date_field  field having an unconventional name', () => {
    it('should generate a valid SQL query', (done) => {
      // TEST
    });
  });
});

@arnaudbesnier
Copy link
Member

Plus, not sure this PR fixes this issue:
#273

Co-Authored-By: Arnaud Besnier <arnaudibesnier@gmail.com>
@VincentMolinie
Copy link
Member

This PR inspired me for the fix. I close it in favor of this one: #301
Thanks a lot @Jekiwijaya for your help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[*] Charts - Charts may have wrong field mapping field to sequelize model. Camelcase Name not found
3 participants