talha-asad / mongoose-url-slugs

Create URL compatiable slugs on mongoose models, ensuring uniqueness.
MIT License
40 stars 22 forks source link

Possible to use the plugin on a subdocument? #41

Open trekinbami opened 6 years ago

trekinbami commented 6 years ago

Hi,

const CourseSchema = new Schema({
  title: {
    type: String,
    required: true
  },
  videos: [VideoSchema],
});

CourseSchema.plugin(URLSlugs('title');
const Course = mongoose.model('course', CourseSchema);

module.exports = Course;

This is pretty obvious. This is the model for a course.

But now I want to run the plugin for the VideoSchema (which doesn't have a Model), because the videos also have title that needs to be slug-i-fied (don't know if that's a word).

Is this possible?

talha-asad commented 6 years ago

Did you try dot notation? If not that could be added I guess.

On Dec 21, 2017 11:05 PM, "trekinbami" notifications@github.com wrote:

Hi,

`const CourseSchema = new Schema({ title: { type: String, required: true }, videos: [VideoSchema], });

CourseSchema.plugin(URLSlugs('title');`

This is pretty obvious. But now I want to run the plugin for the VideoSchema, because the videos also have title that needs to be slug-i-fied (don't know if that's a word).

Is this possible?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/talha-asad/mongoose-url-slugs/issues/41, or mute the thread https://github.com/notifications/unsubscribe-auth/AC1zVr8xs_F5xLcq2a9BZQ5qBOQQHDM3ks5tCp3UgaJpZM4RKKlh .

trekinbami commented 6 years ago

I tried

CourseSchema.plugin(URLSlugs('videos.title', { path: 'videos.slug' }));

But didn't seem to do anything, unfortunately.

hakkurishian commented 5 years ago

Is there any update on this? I'm facing the same issue. If not, is it possible to generate slugs manually in the same way as they are created automatically using the packages API?