0

I seem to have this error, and I'm not doing anything special:

NameError (undefined method `message_id_equals' for class `ActiveRecord::Relation')

Why? Here is the context:

@user_has_message = UserHasMessages.user_id_is(current_user.id).message_id_is(@message.id)

irb(main):012:0> UserHasMessages
=> UserHasMessages(id: integer, user_id: integer, message_id: integer, is_sender: boolean, created_at: datetime, updated_at: datetime)
fresskoma
  • 25,481
  • 10
  • 85
  • 128
Satchel
  • 16,414
  • 23
  • 106
  • 192
  • Please post the relevant pieces of your UserHasMessages class. – mnelson Mar 28 '11 at 02:43
  • @mikeonrails -- you mean the attributes? I output them from the console in the snippet above...let me know...thanks! I thought rd_searchlogic should allow me to do this.... :( – Satchel Mar 29 '11 at 00:38
  • I've never seen `user_id_is` or anything like that. Where is that defined? – mnelson Mar 29 '11 at 02:11

1 Answers1

0

You can't chain those together like that. You're called user_id_is on UserHasMessages, which returns an ActiveRecord response which doesn't contain a method for message_id_is. I don't really know what these methods are, but my guess is that they aren't scopes or it would allow you to chain like that.

Can't you do:

@user_has_message = UserHasMessages.where(:user_id => current_user.id, :message_id => @message.id)

To get the same effect?

ctide
  • 5,217
  • 1
  • 29
  • 26