0

I was using this query to fetch a property with nested resources

@property=Property.includes(rooms: [:photos]).where(id: params[:id]).first

The above works. But now I want to use friendly_id. So I tried @property=Property.includes(rooms: [:photos]).friendly.where(id: params[:id]).first which didnt work. All docs for friendly_id uses find instead of where but here how can I make it work?

Abhilash
  • 2,864
  • 3
  • 33
  • 67

2 Answers2

2

You can just filter on the column you use for the friendly_id, usually named slug

Property.includes(roomes: [:photos]).where(slug: params[:id]).first
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
1

no, it can't, after check the gem's source code, find that the friendly_id gem doesn't override the activerecord's where method.

And if you use friendly_id, why still query the id?

You can directly query the slug column.