What you're doing is fine, pluck(:rel)
will always return an array. If you know you only want one rel, just do
event_rel = current_user.events(:e, :rel).where(id: event_id).limit(1).pluck(:rel).first
If you're using the master branch from github, you can use first_rel_to
method, which (along with match_to
) is changing the way I'm using the gem lately.
event_rel = current_user.events.first_rel_to(event_id)
The ability to give it an ID was added a couple days ago, it won't work if you're pulling from Rubygems. The version of the method in 3.0.4 doesn't accept an ID, it only accepts a full node. If you happen to have the node loaded, you can do event_rel = current_user.events.first_rel_to(event)
in the released version.
If you don't want to use pluck, you can do event_rel = current_user.events.where(id: event_id).
limit(1).each_rel.first
. Just be aware that that's going to return every rel between those two nodes to Ruby if you omit limit(1)
, so don't use it unless you know you're only going to get one back. I usually add limit(1)
when I'm doing this, even if I only think I'm going to get one rel back, cause I like to be safe.
I suggest you point your Gemfile at the most recent commit in Github, just read through the new section in the wiki about the changes in 4.0. It's stable and the new features are so cool.