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 6099063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:13:48+00:00 2026-05-23T13:13:48+00:00

Here is an extract of the schema I actually have Software: columns: title: type:

  • 0

Here is an extract of the schema I actually have

Software:
  columns:
    title:
      type: string(255)
    id_publisher:
      type: integer
    id_developper:
      type: integer

Company:
  columns:
    name:
      type: string(255)
    nationality:
      type: string(255)

As you can see, my Software model has two external references: publisher and developper. My whish would like to create a one to many relation for each of these two references. Problem is they are both companies.

I first tried something like shown below on my Software model, but the relation works only for the first local reference id_publisher.

relations:
  Company:
    type: one
    foreignType: many
    local: [id_publisher, id_developper]
    foreign: id

Then I tried that (always on the Software Model):

relations:
  Publisher:
    class: Company
    type: one
    foreignType: many
    local: id_publisher
    foreign: id
  Developper:
    class: Company
    type: one
    foreignType: many
    local: id_developper
    foreign: id

But when I execute a query which count the number of soft linked to a company…

public function findAllQuery(Doctrine_Query $q = null) {
    $q = Doctrine_Query::create()
                    ->select('c.*, COUNT(s.id) AS count_software')
                    ->from('Company c')
                    ->leftJoin('c.Software s')
                    ->groupBy('c.id');

    return $q;
}

…only publishers are take into account in the COUNT clause.

So finally, my question is, how to deal with multiple one-to-many relations of a same model ??
Thanks for your time !

  • 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-23T13:13:49+00:00Added an answer on May 23, 2026 at 1:13 pm

    maybe you should try to add a foreign alias to tell doctrine which relation to deal with when firing your query:

    relations:
      Publisher:
        class: Company
        type: one
        foreignType: many
        foreignAlias: PublishedSoftware
        local: id_publisher
        foreign: id
      Developer:
        class: Company
        type: one
        foreignType: many
        foreignAlias: DevelopedSoftware
        local: id_developer
        foreign: id
    

    And in your query you have to join both relations and sum the individual counts:

    $q = Doctrine_Query::create()
         ->select('c.*, COUNT(ps.id)+COUNT(ds.id) AS count_software')
         ->from('Company c')
         ->leftJoin('c.PublishedSoftware ps')
         ->leftJoin('c.DevelopedSoftware ds')
         ->groupBy('c.id')
     ;
    

    The doctrine default is to use the model name as identifier for the relation, so if using more then one relation to the same model you really should rename at least one to let doctrine now what you’re meaning. Without this you won’t be able to just retrieve the collection of published software like so:

    $pubSoftware = $myCompany->getPublishedSoftware();
    $devSoftware = $myCompany->getDevelopedSoftware();
    

    What Doctrine is not capable of (IMHO) is to treat both relations to the same model as one. So a call:

    $allSoftware = $myCompany->getSoftware();
    

    won’t retrieve all related software on a multi-relation model but only those which can be retrieved by the relation called Software.

    Hope that helps,

    ~~~ Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a simple form (only extract fields here) but for some reason the JQserilization
I have a following string and I want to extract image123.jpg. ..here_can_be_any_length and_here_any_length/image123.jpg and_here_also_any_length
I have the following string: cn=abcd,cn=groups,dc=domain,dc=com Can a regular expression be used here to
I have an XML schema that I need to extract values from but I
Here is an extract from item 56 of the book C++ Gotchas: It's not
i want to extract some text in certain website. here is web address what
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is an extract from the XML: <?xml version=1.0 encoding=utf-8?> <usa_map_locator> <map_data> <state> <id>2</id>

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.