dm-redis-adapter
dm-redis-adapter copied to clipboard
DM self-referential associations not working
Please excuse me if this is actually not a problem as I am a bit new to both DataMapper and Redis. However I am following the example code in the DataMapper Associations documentation (http://datamapper.org/docs/associations.html) for creating a Twitter-like follower + followed self-referential association in my User model.
This pastie should illustrate the problem: http://pastie.org/2943832
As you can see, when the association is first created, user1 ends up following himself along with the user he was intended to follow, user2 believes she has one follower, but can't seem to find any links_to_followers. Furthermore, unfollowing seems to leave an orphan association on the followed user's side of the association, and just generally seems to make a mess of things.
It seems that the association isn't being stored in/queried from Redis properly, or perhaps it simply isn't possible to store such a relationship in Redis?
Hello disbelief!
It is possible to store this relationship in redis, but it looks to me as though the adapter isn't handling the join model correctly. I'll have a closer look at this and let you know what I find.
Thanks Dan!
In the meantime, I've implemented my user graph directly via Redis commands, more or less as described in this Redis Cookbook recipe: http://rediscookbook.org/implement_a_social_graph.html
However I would obviously prefer to do it the DM way, so I'm looking forward to what you come up with.