0
目前我有数据库模型并可以填充数据模型:DataMapper的许多-to-many关联
user.persons << person
group.functions << function
group.classificationlevels << clasfication
user.groups << group
这些都是我使用目前型号为掌握相关的数据彼此:
module Core_authentication
class User
include DataMapper::Resource
property :id, Serial
property :username, String, :required => true, :unique => true
property :password, BCryptHash, :required => true
property :email, String, :format => :email_address, :required => true
property :created_at, DateTime
property :updated_at, DateTime
#Creating join tables to link to group and person information
has n, :persons, :through => Resource
has n, :groups, :through => Resource
def username= new_username
super new_username.downcase
end
end
class Group
include DataMapper::Resource
property :id, Serial
property :groupname, String, :required => true
#Another jointable link group to link to functions and classification levels
has n, :functions, :through => Resource
has n, :classificationlevels, :through => Resource
has n, :users, :through => Resource
def groupname= new_group
super new_group.downcase.capitalize!
end
end
class Person
include DataMapper::Resource
property :id, Serial
property :firstname, String
property :lastname, String, :required => true
property :adress, String
property :postcode, String, :length => 6, :required => true
property :telefoon, String
property :created_at, DateTime
property :updated_at, DateTime
has n, :users, :through => Resource
def firstname= new_firstname
super new_firstname.downcase.capitalize!
end
def lastname= new_lastname
super new_lastname
end
end
class Function
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :groups, :through => Resource
end
class Classificationlevel
include DataMapper::Resource
property :id, Serial
property :levelcode, Integer
property :name, String
has n, :groups, :through => Resource
end
end
我想获得他们所属的用户组,以及与每个组关联的分类级别。
我尝试了多种方式来做到这一点,并且在网络上四处看了一下,但是我无法找到一个关于如何做到这一点的明确解释,所以我无法得到它的工作。
谢谢,我终于明白了!但是,如果我在一个模块命名空间内工作,它的工作方式是什么? –
对象应该是相同的,你只需要在模块名称的前面。 – phillbaker