Hi,

I wanted to build a View listing all nodes a user (given by a user-id argument) has flagged. First I did this by having a flag-relationship to the node, and a user-relationship to the flag, and then having an argument on the user-id.

However, this seemed like a bit unnecessary, as I wasn't really interested in anything on the user-table, I just wanted to restrict the flags to those made by a specific user-id, which is already present in the flag_content table.

So, I've made a tiny addition to views_data, that allows arguments on flag_content.uid. I know that the functionality this offers is available already by means of a user-relationship, but sometimes it's nice to avoid too many relationships..

Regards
Morten

Comments

quicksketch’s picture

Thanks, this seems like a reasonable request. I've found a few places in Views where this inconsistency exists. I don't think there's a "User: UID" field for example, but there is a "Node: NID". I'll wait until I've had a chance to apply it and see how it "feels" before I know for sure if I'll be adding it to the project.

q0rban’s picture

Title: Allow Views Arguments on flag user id » Add uid as argument, field, and filter in Views
StatusFileSize
new1.43 KB

I agree with this. This is how the node integration for Views module does it: http://drupalcode.org/project/views.git/blob/refs/heads/7.x-3.x:/modules...

You'll see there that node module doesn't just have the relationship, but also has filter, argument and field for the uid column. This allows you to operate on the uid without having to join to the user table.

Currently, for Flag module, if you want to get the uid into either a field, argument, or filter, you have to add two relationships, which amounts to two joins. This is unnecessary since the data exists right in the flag_content table itself—there is no need to do a join to retrieve it. The node module integration makes this clear in the description as well:

The user authoring the content. If you need more fields than the uid add the content: author relationship

Attached patch follows this model, adding UID as a filter, argument, and field, and alters the title and help text to make this clear.

joachim’s picture

Status: Needs review » Fixed

Looks good to me. Thanks for the patch!

Issue #1331614 by q0rban, fangel: Added uid on flag_content table as argument, field, and filter in Views.

Also backported to 6-2 and 6-1 branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.