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