Skip to content

Conversation

GuillaumeCisco
Copy link
Contributor

@GuillaumeCisco GuillaumeCisco commented Jan 15, 2021

This Pr works with:

How to test?

Please follow in the right order theses steps, as there is still an issue with the forestadmin-server update

  1. Switch to the fix-primary-foreign-key-to-primary-key on every projects
  2. Launch forestadmin-server and forestadmin
  3. In the forest-express project, run yarn build:watch
  4. In the forest-express-sequelize, run yarn link forest-express, then yarn build:watch
  5. Create a postgresql database with this dump:
create table if not exists customer
(
	id serial not null
		constraint customer_pk
			primary key,
	name varchar not null
);

create unique index if not exists customer_id_uindex
	on customer (id);

create table if not exists picture
(
	name varchar not null,
	customer_id integer not null
		constraint picture_pk
			primary key
		constraint picture_customer_id_fk
			references customer
);

- BE CAREFUL HERE
  1. Create a project thanks to the onboarding frontend, BUT DO NOT LAUNCH IT
  2. link your project to forest-express-sequelize with yarn link forest-express-sequelize
  3. Launch your project

Pull Request checklist:

  • Write an explicit title for the Pull Request, following Conventional Commits specification
  • 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

@forest-bot
Copy link
Member

@GuillaumeCisco GuillaumeCisco changed the title fix: fix record creation with unconventional pk field acting as a fk toward an unconventional pk fix: fix record creation with unconventional pk field acting as a fk Jan 19, 2021
@GuillaumeCisco GuillaumeCisco force-pushed the fix-primary-foreign-key-to-primary-key branch from 1469c4d to bf4760f Compare January 21, 2021 16:18
});

_.remove(fields, (field) =>
_.includes(fieldNamesToExclude, field.columnName) && !field.primaryKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

primaryKey does not exist, but isPrimaryKey does.
Neithertheless, we still need to remove it for a better user experience.

@GuillaumeCisco GuillaumeCisco force-pushed the fix-primary-foreign-key-to-primary-key branch from effb94e to 84735fd Compare January 26, 2021 10:59
@GuillaumeCisco GuillaumeCisco force-pushed the fix-primary-foreign-key-to-primary-key branch from 92d9a9d to 19fd728 Compare January 27, 2021 10:52
@GuillaumeCisco GuillaumeCisco marked this pull request as ready for review January 27, 2021 14:38
@GuillaumeCisco GuillaumeCisco force-pushed the fix-primary-foreign-key-to-primary-key branch from a516d3d to ad3d704 Compare February 10, 2021 14:12
SteveBunlon
SteveBunlon previously approved these changes Feb 15, 2021
Comment on lines 1 to 3
exports.primaryKeyIsForeignKey = (association) =>
Object.values(association.source.rawAttributes).filter((attr) =>
attr.field === association.source.primaryKeyField).length > 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

[PROPOSAL] Knowing this will be the only one function of the this file, we might want to export it as it is, and packed in an object.
module.exports = (association) => ..

SteveBunlon
SteveBunlon previously approved these changes Feb 17, 2021
@GuillaumeCisco GuillaumeCisco force-pushed the fix-primary-foreign-key-to-primary-key branch from 34b876b to f684229 Compare February 19, 2021 15:40
@GuillaumeCisco GuillaumeCisco merged commit d3779b7 into master Feb 22, 2021
@GuillaumeCisco GuillaumeCisco deleted the fix-primary-foreign-key-to-primary-key branch February 22, 2021 07:13
forest-bot added a commit that referenced this pull request Feb 22, 2021
## [6.7.9](v6.7.8...v6.7.9) (2021-02-22)

### Bug Fixes

* fix record creation with unconventional pk field acting as a fk ([#598](#598)) ([d3779b7](d3779b7))
@forest-bot
Copy link
Member

🎉 This PR is included in version 6.7.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

forest-bot added a commit that referenced this pull request Feb 22, 2021
# [7.0.0-beta.11](v7.0.0-beta.10...v7.0.0-beta.11) (2021-02-22)

### Bug Fixes

* fix record creation with unconventional pk field acting as a fk ([#598](#598)) ([d3779b7](d3779b7))
* support foreign and primary key column ([#630](#630)) ([2a289b8](2a289b8))
* **search:** don't convert float values to bigint ([75c1517](75c1517))
* **search:** handle large numbers in search queries ([c0c1c70](c0c1c70))
* **search:** handle large numbers in search queries ([#621](#621)) ([ec6ab89](ec6ab89))
* **search:** handle tables that contain floats and bigints ([7ac2fe1](7ac2fe1))
* **search:** revert changes when numbers are below MAX_SAFE_INTEGER ([1d95021](1d95021))
@forest-bot
Copy link
Member

🎉 This PR is included in version 7.0.0-beta.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants