title: DataMapper many-to-many association
body: <p>At the moment I have the database model up and can populate the models with data:</p>
  
  <pre><code>   user.persons &lt;&lt; person
      group.functions &lt;&lt; function
      group.classificationlevels &lt;&lt; clasfication
      user.groups &lt;&lt; group
  </code></pre>
  
  <p>These are the models I am using at the moment for getting the data associated with each other:</p>
  
  <pre><code>module Core_authentication
  
    class User
      include DataMapper::Resource
  
      property :id, Serial
      property :username, String, :required =&gt; true, :unique =&gt; true  
      property :password, BCryptHash, :required =&gt; true 
      property :email, String, :format =&gt; :email_address, :required =&gt; true
      property :created_at, DateTime
      property :updated_at, DateTime
  
      #Creating join tables to link to group and person information
      has n, :persons, :through =&gt; Resource
      has n, :groups, :through =&gt; Resource
  
      def username= new_username
        super new_username.downcase
      end
  
    end 
  
    class Group
      include DataMapper::Resource
  
      property :id, Serial
      property :groupname, String, :required =&gt; true
  
      #Another jointable link group to link to functions and classification levels
      has n, :functions, :through =&gt; Resource
      has n, :classificationlevels, :through =&gt; Resource
      has n, :users, :through =&gt; 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 =&gt; true
      property :adress, String
      property :postcode, String, :length =&gt; 6, :required =&gt; true
      property :telefoon, String
      property :created_at, DateTime
      property :updated_at, DateTime
  
      has n, :users, :through =&gt; 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 =&gt; Resource
  
    end  
  
    class Classificationlevel
      include DataMapper::Resource
  
      property :id, Serial
      property :levelcode, Integer
      property :name, String
  
      has n, :groups, :through =&gt; Resource
  
    end
  
  end
  </code></pre>
  
  <p>I want to get a user's groups they are a member of, and the classification level that is associated with each group.</p>
  
  <p>I tried multiple ways of doing this, and also looked around on the web, but I cannot find a clear explanation on how I must do this, and so I can't get it working.</p>