Hi Everyone,
I have 2 models:
class Video < ActiveRecord::Base
belongs_to :categories, :foreign_key => "category", :class_name => "Category"
end
class Category < ActiveRecord::Base
has_many :videos
end
This is fine so far, in my videos controller for the index page I have:
def index
@videos = Video.all(:joins => :categories)
etc, etc
end
The above produces the following SQL Query: SELECT videos
.* FROM videos
INNER JOIN categories
ON categories
.id = videos
.category
Which is fine up to a certain point, basically I need to get the category name (a field in that table) that way I don't have to do another call in the view to get category name based on the category id. Any ideas?
Thank you, and yes I am new to ruby, I tried reading the API but couldn't find much help there.