forest-express-mongoose icon indicating copy to clipboard operation
forest-express-mongoose copied to clipboard

[+] Polymorphism Mongoose refPath Support

Open ItsMrAkhil opened this issue 8 years ago • 12 comments

cancelledBy: { type: mongoose.Schema.Types.ObjectId, refPath: 'cancelledByUserType' }

This kind of refPath instead of ref is not working. I know it's a new feature. It would be great if this feature is provided.

ItsMrAkhil avatar May 14 '17 10:05 ItsMrAkhil

Hi @ItsMrAkhil, thank you for the idea!

Can you provide a small piece of code to help us reproduce and implement the refPath support?

🌲🌲🌲

arnaudbesnier avatar May 15 '17 07:05 arnaudbesnier

Hi, @arnaudbesnier Let me explain it in a clear way.

Let's say I have three mongoose schemas like below


AdminSchema: 
{
  name: { type: String },
  email: { type: String },
}

UserSchema:
{
  name: { type: String },
  email: { type: String },
}

BookingSchema:
{
  item: { type: mongoose.Schema.Types.ObjectId, ref: 'item' }, // Currently supported by forest admin
  createdBy: { type: mongoose.Schema.Types.ObjectId, refPath: 'createdByUserType' }, // Currently not supported by forest admin
  createdByUserType: { type: String, enum: ['Admin', 'User'] },
}

If we want to create a booking and we have only one user schema we all set to go with current forest admin. But if we do not know who is going to create a booking and you want mongoose population to work properly you need to use refPath provided by the mongoose.

And now the problem with the current forest admin is -> it is not showing the related details of createdBy field in the document. In this place, it is showing the object id which is not so great. Whereas I am expecting the populated document details (So, that I can choose whatever field I want. In my case it is name in both schemas AdminSchema as well as in UserSchema ). I am attaching an image below as an example. screen_forest_admin_error

In the image, paymentBy has to be populated based on paymentByUserType.

Best regards, Akhil

ItsMrAkhil avatar May 16 '17 08:05 ItsMrAkhil

Thanks @ItsMrAkhil, it is crystal clear. This is a feature we really need to have. I'll add a story for this in our backlog but I cannot provide any ETA at this time.

arnaudbesnier avatar May 16 '17 09:05 arnaudbesnier

Hi @arnaudbesnier Any updates on this ? Is it still planned in your backlog ?

BenjaminG avatar Mar 21 '18 10:03 BenjaminG

waiting for this

akashdeepsinghal avatar Jul 04 '18 15:07 akashdeepsinghal

Hey @BenjaminG @akashdeepsinghal This feature is not yet planned in our 6-weeks roadmap. This is something more and more customers are asking for (accross the stacks). I cannot provide any ETA but it could be prioritised in a few months.

arnaudbesnier avatar Jul 05 '18 14:07 arnaudbesnier

Hi @akashdeepsinghal, can you precise me your Forest Admin project name to note your request in our roadmap? You can contact me at [email protected]. Thanks

louisteenbrink avatar Jul 09 '18 12:07 louisteenbrink

I have got a workaround without referring the object: Following is an example:

const mongoose = require('mongoose'); const schema = mongoose.Schema({ user: { type: mongoose.Schema.Types.ObjectId, // refer as the mongoose ObjectID type // ref: 'users', // avoid referring the object to any other collection required: true }, planName: { type: String ....................

anilprasad avatar Aug 25 '18 11:08 anilprasad

@arnaudbesnier It's been a couple of years since I open this issue. Still looking forward to the solution. Any ETA on this?

ItsMrAkhil avatar May 07 '19 10:05 ItsMrAkhil

@ItsMrAkhil, I am sorry to tell you that there is no ETA for this feature request. We'd love to have the time to implement this feature, but we're still a small team focused on other top priorities.

Thanks for your patience.

arnaudbesnier avatar May 09 '19 06:05 arnaudbesnier

@arnaudbesnier Can I create my own PR for this? Because it will help me a lot if I have this feature.

ItsMrAkhil avatar May 09 '19 07:05 ItsMrAkhil

Yes you can fork the repo and suggest changes that would support this feature.

arnaudbesnier avatar May 09 '19 07:05 arnaudbesnier