Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird issue with friendship table and class/instance equality #24

Open
elan opened this issue Apr 8, 2012 · 2 comments
Open

Weird issue with friendship table and class/instance equality #24

elan opened this issue Apr 8, 2012 · 2 comments

Comments

@elan
Copy link

elan commented Apr 8, 2012

The invited_by? and invited? methods aren't working for me because of this line:

friendship.friendable == user

For some reason when I access a User instance via the association, even though I get something back which appears to be the same class, but isn't, iow (assuming the friendable ID is 1):

User.find(1) == friendship.friendable # false!

This is under Webrick, Rails 3.0.10, Amistad 0.8.

The most bizarre thing is that it works in the Rails console just fine, and it works in Webrick ONCE before failing.

I hesitated to post this because I am clearly insane, but it's also 100% reproducible.

@killthekitten
Copy link

+1 from me, it's weird thing. In console it works great, but not in real application.

@killthekitten
Copy link

I think it's because of identifying objects in ruby\rails. User, which been called as User.find(1) has one object id, and the other user, from friendship.friendable is the other, so comparing them is meaningless.

I forked amistad, and fixed this bug by comparing User.id and friendable.id. But also, I think that using :inverse_of in relations can do the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants