#411 ✓resolved
Bryan Larsen

Hobo scope should work with has_many :through

Reported by Bryan Larsen | April 24th, 2009 @ 09:59 PM | in Hobo 1.0 - Final

The agility tutorial gives this example in "Granting Write Access to Others":

has_many :contributor_memberships, :class_name => "ProjectMembership", :scope => :contributor
has_many :contributors, :through => :contributor_memberships, :source => :user

The problem is that doesn't actually work. contributor_memberships applies the scope, but contributors does not.

See discussion here: http://groups.google.com/group/h...

Comments and changes to this ticket

  • Owen

    Owen April 25th, 2009 @ 07:43 PM

    • Assigned user set to “Bryan Larsen”


    Can you add a Barquin suggested priority of '1' to this?



  • Tom Locke

    Tom Locke April 27th, 2009 @ 03:37 PM

    • State changed from “new” to “open”
  • Bryan Larsen

    Bryan Larsen May 1st, 2009 @ 09:15 PM

    • State changed from “open” to “resolved”

    I pushed a fix. I also updated agility to demonstrate the "optional" part of the tutorial, and added a selenium test. The test also conveniently tests auto-complete.

  • Txinto

    Txinto April 16th, 2013 @ 04:51 PM

    Hi, I have found this problem also in the Hobo 2.0.

    Look at this:

    ... has_many :contributor_memberships, :class_name => "ProjectMembership", :scope => :contributor has_many :contributors, :through => :contributor_memberships, :source => :user, :scope => :contributor ...

    And in the console:

    p=Project.find(1) Project Load (0.3ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT 1 [["id", 1]] ... p.contributor_memberships.count Creating scope :contributor. Overwriting existing method ProjectMembership.contributor.
    (0.5ms) SELECT COUNT(*) FROM "project_memberships" WHERE "project_memberships"."project_id" = 1 AND (project_memberships.contributor = 't') => 2 ... p.contributors.count (0.2ms) SELECT COUNT(*) FROM "users" INNER JOIN "project_memberships" ON "users"."id" = "project_memberships"."user_id" WHERE "project_memberships"."project_id" = 1 => 3

    So, the problem is that the "through" relationship does not propagate the "scope" condition.

    Best regards.


Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป