Issue with Objection.js Relation Mapping

59 Views Asked by At

I am currently working on setting up a relationship in Objection.js between the Article and Chat models in my application. I have encountered an error related to the relation mapping, specifically in the definition of the join.from property.


channels: {
  relation: BaseModel.HasManyRelation,
  modelClass: Chat,
  join: {
    from: (builder) => {
      if (builder.parentModel().parent_id !== null) {
        return 'article.parent_id';
      }
      return 'article.id';
    },
    to: 'Chat.articleId',
  },
},

The error message I'm receiving is: Article.relationMappings.Chat: join.from must have format TableName.columnName. For example "SomeTable.id".

I've tried several approaches to resolve this error, but none of them seem to work. If anyone has experience with Objection.js or has encountered a similar issue, I would greatly appreciate any insights or suggestions you might have to offer.

0

There are 0 best solutions below