M2_
M2_

Reputation: 317

friendly_id and real id

Is there any way to get the real id column from a model that is modified with friendly_id?

I don`t want to make another db query for it, in performance reasons.

Upvotes: 3

Views: 1135

Answers (2)

Voldy
Voldy

Reputation: 12868

Broadly speaking friendly_id modifies to_param and find methods. Next should work:

@affiche = Affiche.find(params[:id]) # params[:id] is a slug
@id = @affiche.id

Upvotes: 5

Mattias Wadman
Mattias Wadman

Reputation: 11425

Have you tried attributes["id"]? e.g: Model.first.attributes["id"]

Upvotes: 0

Related Questions