friendly_id on belongs_to model

196 views Asked by At

I have a devise User model and a Profile model which belongs_to the User

class Profile < ApplicationRecord
    belongs_to :user
end

The User model has a added column called name which stores the users name.

Im using friendly_id gem and want to apply it to the Profile model like so:

class Profile < ActiveRecord::Base
  belongs_to :user
  extend FriendlyId
  friendly_id :name, use: :slugged
end 

But rather than create another column in the Profile model called name, i want to use the User model column name here, which the profile belongs_to.

1

There are 1 answers

0
Igor Springer On BEST ANSWER

An answer from friendly_id repository owner to a similar question from Github issue:

Sorry, not going to do this. This was how FriendlyId 3.x and below worked. If you have very large tables, performance is significantly worse with the slug in a separate table.

So it a nutshell, the slug must be placed in the same table.