Skip to content

Instantly share code, notes, and snippets.

@ctdk
Created June 6, 2009 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctdk/124738 to your computer and use it in GitHub Desktop.
Save ctdk/124738 to your computer and use it in GitHub Desktop.
# 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