Why do certain queries return records with [] and some Nil?
I am trying to figure out why if I run a statement like:
user.articles # yields '[]' if the user has no articles
but if I write a statement like this:
user.likes # yields Nil if empty
likes would be a method in the User model and would look something like this:
def likes
Likes.find_by_user_id(id)
end
Likes would be a join table containing a user_id and article_id.
What I'd like to do in my view is make these sort of statements:
user.likes.count
Actually now that I think of it, it would be great to do this:
@user.articles.likes
and get a array of the articles that a user likes.
Make sense?
I'm getting the feeling that this calls for a :through parameter in my models, but I haven't gotten the hang of that yet, and don't know if it's appropriate.