Gurmukh Singh
Gurmukh Singh

Reputation: 2017

friendly_id on belongs_to model

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.

Upvotes: 0

Views: 177

Answers (1)

Igor Springer
Igor Springer

Reputation: 496

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.

Upvotes: 3

Related Questions