Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 350493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:33:19+00:00 2026-05-12T11:33:19+00:00

I wish to persist some extra data in a many-to-many relationship by having some

  • 0

I wish to persist some extra data in a many-to-many relationship by having some extra fields in the association table. For instance, I would like to keep track of what role a user has in a network, such as ‘member’, ‘moderator’, ‘admin’ etc. I would also like to keep track of when he/she joined the network. Now, what I am looking for is an efficient way to retrieve these extra fields using Doctrine. A typical, though very simplified, DQL-query might look like so:

// find.network.by.slug
Doctrine_Query::create()
    ->select('*')
    ->from('Network n')
    ->leftJoin('n.Members u')
    ->where('n.slug = ?');
  1. So, given that I have a User from the Members relation, is there any way I can "backtrack" into the NetworkMembers relation and fetch the extra fields?

  2. If not, how do I re-arrange my schema to enable me to do this efficiently?

    (i.e. I don’t want to iterate over all networks the member has to find the network I started from and fetch the role and member_since field).

Code illustration of my problem:

$networkTable = Doctrine::getTable('Network');
$network = $networkTable->executeOne('find.network.by.slug', $slug);
$members = $network->Members;
foreach($members as $member) {
   // How do I access the fields in the NetworksMember association?
}

Schema below:


User:
  tableName: users
  columns:
    user_id:
      name: user_id as userId
      type: integer(8)
      unsigned: 1
      primary: true
      autoincrement: true
    username:
      type: string(30)
      notnull: true
      unique: true
  relations:
    Networks:
      class: Network
      local: user_id
      foreign: network_id
      refClass: NetworkMembers
      type: many

Network:
  tableName: networks
  actAs:
    Sluggable:
      unique: true
      fields: [name]
      canUpdate: true
    Timestampable:
  columns:
    id:
      type: integer(8)
      unsigned: 1
      primary: true
      autoincrement: true
    name:
      type: string(64)
      notnull: true
  relations:
    Members:
      class: User
      type: many
      refClass: NetworkMembers
      local: network_id
      foreign: user_id
      foreignAlias: Networks
      foreignType: many

NetworkMembers:
  actAs:
    Timestampable:
      created:
        name: member_since as memberSince
        type: timestamp
      updated:
        disabled: true
  columns:
    networkId:
      name: network_id as networkId
      type: integer(8)
      unsigned: 1
      primary: true
    userId:
      name: user_id as userId
      type: integer(8)
      unsigned: 1
      primary: true
    role:
      type: enum
      values: [member, moderator, admin]
      default: member
  relations:
    Network:
      type: one
      local: network_id
      foreign: id
    Member:
      class: User
      type: one
      local: user_id
      foreign: user_id

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:33:20+00:00Added an answer on May 12, 2026 at 11:33 am

    I got it myself, just had to take a slight different approach:

    // find.network.by.slug
            Doctrine_Query::create()
                ->select('*')
                ->from('Network n')
                ->leftJoin('n.NetworkMembers nm')
                ->leftJoin('nm.Member u')
                ->leftJoin('n.Founder f')
                ->leftJoin('n.Icon icon')
                ->where('n.slug = ?')
    
    // later:
    $members = $this->network->NetworkMembers;
    foreach($members as $networkMember) {
       echo $networkMember->Member->username;
       echo $networkMember->role; // Here I can access the 
                                  // NetworkMember association directly
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to use a join across some tables but am having some difficulty
I wish for a class A to contain some data, and class B will
I wish to use Google custom search and in particular would like to have
I wish to be able to generate URL variables like this: http://example.com/195yq http://example.com/195yp http://example.com/195yg
Really wish i was God, then I would understand what this means: The element
... wish all of you are having a nice Valentine's Day .. For me,
I'm looking to build my first web service and I would like to be
I wish to request data from a web service endpoint( say http://www.example.com ) using
I wish to create json looking like: {man: { name:emil, username:emil111, age:111 } }
I am working with Visual Studio Coded UI Tests, and wish to persist tweaks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.