Search code examples
activerecordruby-on-rails-4

Weird behaviour in model (Ruby on Rails 4)


I've a weird behaviour in my model code, but I am not sure if this is my problem or is it some weird issue with Ruby on Rails.

I've an associated has_many :chat_user #linked to ChatUser

and I've defined

Class A

def guest 

 chat_user #returning chat_user from has_many

end

end

I've 2 records of ChatUser which is linked to this model class

When I called object of Chat A .chat_user -> count and each return 2 records.

When I called object of .guest -> count return 2, but each loop only once!

What could be the issue? I am using Rails 4.0.0 with Puma server.


Solution

  • I found the issue, I've actually returned a custom where query with limit 1 applied to chat_user, hidden in a function.