Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concatenated slugs #9

Closed
FarazPatankar opened this issue May 26, 2019 · 8 comments
Closed

Concatenated slugs #9

FarazPatankar opened this issue May 26, 2019 · 8 comments
Labels
question Further information is requested

Comments

@FarazPatankar
Copy link

Hey,

I just found this library and it seems great so far. I had a quick question, would it be possible to concatenate two values to form my slug?

As an example, let's assume I am building a job board and I want the slug to be the job title followed by the company name. Could I do something like slug: 'title', 'at', 'company.name'.

Thanks!

@YuriGor
Copy link
Owner

YuriGor commented May 26, 2019

Hi @FarazPatankar!
Yes, it's called compound slug

@YuriGor YuriGor closed this as completed May 26, 2019
@YuriGor YuriGor added the question Further information is requested label May 26, 2019
@FarazPatankar
Copy link
Author

Hey @YuriGor,

Thanks for the quick response but I already tried it and it didn't work. Even in this example, it doesn't, right?

@YuriGor
Copy link
Owner

YuriGor commented May 26, 2019

Most of the tests use compound slugs, so I expect it should work.

If something doesn't work for you there are two cases:

  • you've found a bug - then report it with details on how to reproduce it.
  • you've configured something wrong - then show your code, I'll try to help.

@YuriGor
Copy link
Owner

YuriGor commented May 26, 2019

@FarazPatankar
Copy link
Author

FarazPatankar commented May 26, 2019

I feel like I am missing something. Here's the code:

const JobSchema = new Schema({
  title: {
    type: String, required: true,
  },
  slug: {
    type: String,
    slug: ['title', 'company.name'],
    uniqueSlug: true,
  },
  company: { type: Schema.Types.ObjectId, ref: 'Company' },
});

Shouldn't this add a slug that includes both the job title and the company name? I am only getting the job title as of now.

Does it not work because I am referencing another model? Does it only work for subdocuments?

@YuriGor
Copy link
Owner

YuriGor commented May 26, 2019

I've never tested Mongoose Population feature, but show me the rest of the code.
Do you have some data loaded already before you are trying to update/create a document with a slug?
Ah, you also want the slug to be unique - this will definitely not work.
You may try to use forceIdSlug: true flag and make sure documents are loaded/filled before you are trying to generate a slug.

@FarazPatankar
Copy link
Author

That's all the code I have actually. I am using Forest Admin to add/update the data. It works fine if I use two fields from the JobSchema itself.

I also tried removing doing it with the uniqueSlug property but that didn't help either.

@YuriGor
Copy link
Owner

YuriGor commented May 26, 2019

Well, I can't help you with it right now, refs are not supported yet.
And if I'll implement this feature(I don't promise), it will not be soon.
I expect it will be difficult to keep slug synced with fields from separate collections linked by ref.

In your case i'd recommend to have slug field in each collection, in the job and company separately.
If job slug will be unique - you still will be able to search by this slug, and company slug will be used as an url decoration only, separated by slash:
suberjob.com/my-company/my-job-wsg535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants