norman / friendly_id

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
http://norman.github.io/friendly_id/
MIT License
6.15k stars 591 forks source link

Add a method to return a hash of relationship friendly_ids? #964

Closed aximuseng closed 3 years ago

aximuseng commented 3 years ago

I am using https://github.com/jsonapi-serializer/jsonapi-serializer for an API in my app. I want to use my Friendly IDs to hide the actual DB id.

In the json gem you can call a custom method to get the ids of the relationship. It's an extension of something like this:

class MyModel
  has_many :tasks
end

pry>MyModel.last.task_ids
=> [32475, 32471, 32472, 32473, 32474]

It looks to me that there is no Friendly id equivalent like:

pry>MyModel.last.friendly_task_ids
=> ['task-32475', 'task-32471', 'task-32472', 'task-32473', 'task-32474']

Does this exist in the existing code somewhere?

If not is there an appetite to add this?

I can add these custom methods in all my models but having this built in to Friendly ID would be better.

It seems as 'easy' as adding:

relationship_name.pluck(:slug_column_name)

parndt commented 3 years ago

Does this exist in the existing code somewhere?

If not is there an appetite to add this?

No, we try to keep the maintenance overhead as low as possible so I don't think this is something we want to support. Thanks for checking!

aximuseng commented 3 years ago

No worries - figured I would ask first. I think I may just roll my own Module etc to add this where needed. Right now I am just adding these manually.