Associations that return objects for a particular user

I’m new to Ruby, Rails and this group, so first I’d like to say is
hello and thanks for this awesome language, framework, and community.

I have a graph linked by an edge model using has_many :through like the
one described here:

Users habtm Links (directed edges), and vice versa. I have a table
links_users. So far this all works fine.

The problem is, I want to be able to say, get all children (neighbors
reachable in 1 step from this node) only through links that belong to
a given user
(typically, the current user).

I wrote some methods on Node like this:

def links_as_parent_for(user)
:joins => “INNER JOIN links_users ON links_users.link_id =”,
:conditions => "links_users.user_id = " + +
" AND links.parent_id = " +

def children_for(user)
links_as_parent_for(user).collect { |l| l.child }

This works, but it would be great if this could all act as an
association so that, for example, if the objects were already in memory
it wouldn’t issue an additional SQL query (plus it would be nice to say
node.children and get the right results). I don’t think that
associations can take arguments, but can they check the current user
some other way?

Is this possible? Any suggestions?

Thank you for your responses,

Nick Urban