Cannot create entry from a second-level collection

Expected behavior

I need to create a new entry (funding) from a collection (leads).

In my lead, I choose fundings (Financements) on the left, then I create a new funding. In my form, I can also choose a funder. I’ve got an error in the console when I trigger the CRUD.

Actual behavior

I’ve got this error when I click on Create:

Capture d’écran 2021-01-15 à 14.56.03

Context

  • Forest Express Mongoose Version: ^6.6.3,
  • Project Name: lereacteur-admin
1 Like

Hello @XavierColombel,

Thanks for contacting us!

Just to be sure, what you’re trying to achieve is to add an existing funding to a lead through the related data screen (looking like this screen just below)?

No, I’m trying to add a new funding, from a lead.

@adriguy did you fund any solution ? :sweat_smile:

@XavierColombel :sweat_smile:
I understood what you were talking about, thanks!

But unfortunately I haven’t been able to reproduce it yet.

Can you show us the model definition of collections please?

Fundings:

const schema = mongoose.Schema(
  {
    funder: { type: mongoose.Schema.Types.ObjectId, ref: "Funders" },
    lead: { type: mongoose.Schema.Types.ObjectId, ref: "Leads" },
    documents: [{ type: mongoose.Schema.Types.ObjectId, ref: "Documents" }],
    gocardless: {
      paymentId: String,
    },
    externalReference: String,
    paymentMethod: String,
    paymentStatus: {
      type: String,
      default: "toClaim",
    },
    amount: Number,
    amountAlt: Number,
    vat: Number,
    currency: {
      type: String,
      default: "EUR",
    },
    discountType: {
      type: String,
      default: "none",
    },
    discountValue: Number,
    invoices: [{ type: mongoose.Schema.Types.ObjectId, ref: "Invoicing" }],
    credits: [{ type: mongoose.Schema.Types.ObjectId, ref: "Invoicing" }],
    incomings: [{ type: mongoose.Schema.Types.ObjectId, ref: "Incomings" }],
    refundPaymentId: String,
    chargeDate: Date,
    claimedAt: Date,
    createdAt: {
      type: Date,
      default: Date.now,
    },
    updatedAt: {
      type: Date,
      default: Date.now,
    },
  },
  {
    timestamps: false,
  },
);

module.exports = mongoose.model("Fundings", schema, "fundings");

Leads:

const schema = mongoose.Schema(
  {
    unread: {
      type: Boolean,
      default: true,
    },
    email: String,
    telephone: String,
    firstname: String,
    lastname: String,
    companyName: String,
    birthDate: Date,
    address: String,
    zipCode: String,
    city: String,
    country: String,
    kairos: String,
    cpf: String,
    session: { type: mongoose.Schema.Types.ObjectId, ref: "SessionsApollo" },
    format: String,
    logicalTest: {
      candidate_id: String,
      link: String,
      score: Number,
      result: Object,
    },
    logicalTestStatus: {
      type: String,
      default: "unsent",
    },
    todolist: [Object],
    price: Number,
    currency: {
      type: String,
      default: "EUR",
    },
    infos: String,
    commentsArr: [
      { type: mongoose.Schema.Types.ObjectId, ref: "CommentsLeads" },
    ],
    students: [{ type: mongoose.Schema.Types.ObjectId, ref: "Students" }],
    fundings: [{ type: mongoose.Schema.Types.ObjectId, ref: "Fundings" }],
    funders: [{ type: mongoose.Schema.Types.ObjectId, ref: "Funders" }],
    quotes: [{ type: mongoose.Schema.Types.ObjectId, ref: "Invoicing" }],
    documents: [{ type: mongoose.Schema.Types.ObjectId, ref: "Documents" }],
    mailinglist: Boolean,
    utmSource: String,
    source: String,
    gclid: String,
    fbclid: String,
    referrer: String,
    marketing: {
      step: {
        type: Number,
        default: 0,
      },
      sentAt: {
        type: Date,
        default: Date.now,
      },
    },
    lastMailSent: Date,
    status: String,
    createdAt: {
      type: Date,
      default: Date.now,
    },
    updatedAt: {
      type: Date,
      default: Date.now,
    },
  },
  {
    timestamps: false,
  },
);

module.exports = mongoose.model("Leads", schema, "leads");

I have to say everything was working fine past days. I even rollback my commits and the problem is still the same… And I haven’t touch this collection and/or CRUD files.

Exactly same problem for me
Everything was working for months and yesterday on the afternoon, impossible to create entity from related data creation form

Script crash on Forest side with a null referenceModel
image

Thanks for your help

1 Like

Forest Admin team has fixed the problem ! :v: