Geometry points with same name on related tables prevent data from being displayed

Feature(s) impacted

We recently added an experience table in our DB. It has a foreign key to art_instance table. This is a one to many relation in which an experience can have multiple art instances. Both tables have a coordinate which is a geometry point.

After adding the foreign key, the coordinates of all arts instances AND experiences diseappared on forest (see observed behavior below). If we changed the data type of experience coordinate to string, arts instances coordinates were restored but we coudn’t edit experience coordinates or display them on map (since it’s considered as a string).

I found a fix to change the name of the field to be able to keep them both as geometry point (see expected behavior). This is an issue related only to this data type because we have lots of field with same name on mutliples related tables and never had this issue before. Do you have more informations on this kind of problem or its cause ?

Thanks and have a nice day !

Observed behavior

Here’s our experience and art instance models :

const Experience = sequelize.define('experience', {
    id: {
      type: DataTypes.UUID,
      primaryKey: true,
      defaultValue: Sequelize.literal('uuid_generate_v4()'),
      allowNull: false,
    },
    coordinate: {
      type: DataTypes.GEOMETRY('POINT'),
      allowNull: false,
    },
    radius: {
      type: DataTypes.DOUBLE,
      allowNull: false,
    },
 # [...]
    isValidated: {
      type: DataTypes.BOOLEAN,
      field: 'validate',
      allowNull: false,
    },
    expiresAt: {
      type: DataTypes.DATE,
    },
    createdAt: {
      type: DataTypes.DATE,
      defaultValue: Sequelize.literal('now()'),
    },
  }, {
    tableName: 'experience',
    underscored: true,
    timestamps: false,
  });

  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  Experience.associate = (models) => {
    Experience.belongsTo(models.shopItem, {
      foreignKey: {
        name: 'shopItemIdKey',
        field: 'shop_item_id',
      },
      as: 'shopItem',
    });
    Experience.hasMany(models.art, {
      foreignKey: {
        name: 'experienceIdKey',
        field: 'experience_id',
      },
      as: 'arts',
    });
    Experience.hasMany(models.artInstance, {
      foreignKey: {
        name: 'experienceIdKey',
        field: 'experience_id',
      },
      as: 'artInstances',
    });
  };

  return Experience;
 const ArtInstance = sequelize.define('artInstance', {
    id: {
      type: DataTypes.UUID,
      primaryKey: true,
      defaultValue: Sequelize.literal('uuid_generate_v4()'),
      allowNull: false,
    },
    coordinate: {
      type: DataTypes.GEOMETRY('POINT'),
      allowNull: false,
    },
    createdAt: {
      type: DataTypes.DATE,
      defaultValue: Sequelize.literal('now()'),
    },
    viewNumber: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      allowNull: false,
    },
    expiresAt: {
      type: DataTypes.DATE,
    },
  }, {
    tableName: 'art_instance',
    underscored: true,
    timestamps: false,
  });

  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  ArtInstance.associate = (models) => {
    ArtInstance.belongsTo(models.art, {
      foreignKey: {
        name: 'artIdKey',
        field: 'art_id',
      },
      as: 'art',
    });
    ArtInstance.belongsTo(models.experience, {
      foreignKey: {
        name: 'experienceIdKey',
        field: 'experience_id',
      },
      as: 'experience',
    });
    ArtInstance.belongsTo(models.tours, {
      foreignKey: {
        name: 'toursIdKey',
        field: 'tours_id',
      },
      as: 'tours',
    });
    ArtInstance.belongsToMany(models.user, {
      through: 'favorite',
      foreignKey: 'art_id',
      otherKey: 'user_id',
      as: 'userThroughFavorites',
    });
    ArtInstance.hasMany(models.watch, {
      foreignKey: {
        name: 'artInstanceIdKey',
        field: 'art_instance_id',
      },
      as: 'artInstanceWatches',
    });
    ArtInstance.hasMany(models.issue, {
      foreignKey: {
        name: 'artInstanceIdKey',
        field: 'art_instance_id',
      },
      as: 'artInstanceIssues',
    });
  };

  return ArtInstance;

With no modification, we had no display of coordinates in both art instances and experience :


image

Expected behavior

With this fix on experience model :

    experienceCoordinate: {
      type: DataTypes.GEOMETRY('POINT'),
      allowNull: false,
      field: 'coordinate',
    },

The coordinates are correctly displayed in both art instances and experience :


But why do we have to make this fix to make it work properly ?

Context

• Project name: BavAR[t] 
• Team name: AR[t] Studio 
• Environment name: Development and Production 
• Agent technology: nodejs 
• Agent (forest package) name & version: forest-express-sequelize v9 
• Database type: postgreSQL 
• Recent changes made on your end if any: added foreign key from experience table to art instances table

Hello,

Sorry for the delay, but this required quite a bit of digging.
It would appear that the fact that both columns are Points and share the same name accross the relationship is causing the issue.
A fix is on the way.
I will let you know once released
@Nicolas.M

1 Like

A fix to your issue has been released in the forest-express package, version 10.2.25.
Please upgrade this dependency and let us know if it fixes your issue :pray: