Created
June 6, 2009 07:05
-
-
Save ctdk/124738 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# what breaks | |
<% blogs = @story.user.blogs %> | |
# with: | |
Cannot find the child_model Blogadmin for User | |
# the relationship in User | |
# doesn't work | |
has n, :blogadmins | |
# this doesn't work either | |
#has n, :blogadmins, :class_name => "Blogadmin", :child_key => [:user_id] | |
has n, :blogs, :through => :blogadmins | |
# the relationship in Blogs | |
has n, :blogadmins | |
has n, :admins, :through => :blogadmins | |
# the blogadmin class | |
class Blogadmin | |
include DataMapper::Resource | |
property :blog_id, Integer, :key => true | |
property :user_id, Integer, :key => true | |
property :role_id, Integer #, :key => true | |
# simple version now... | |
belongs_to :blog | |
belongs_to :user | |
# try this out... | |
belongs_to :role | |
end | |
# the code above doesn't work, but this *does* | |
# blogadmins should be the join between "blogs" and "users" | |
bp = self.blogs.get(blog.id) | |
if (bp) | |
bp.blogadmins.each { |b| | |
b.role.perms.each { |p| | |
return true if p.perm == perm | |
} | |
} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment