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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:19:50+00:00 2026-05-15T19:19:50+00:00

Somehow I can’t figure out how to implement the following relations using Doctrine 2

  • 0

Somehow I can’t figure out how to implement the following relations
using Doctrine 2 syntax:

I have Items and Shops. Each item has different price and different
quantity at each shop. So, I have Items table, Shops table and
ItemsAtShops table. How do I reflect the last one in Doctrine?

I guess I need to create ItemsAtShops entity, relates ManyToOne ->
Items and ManyToOne -> Shops, right? But in this case… how do I
conveniently fetch a list of Items at the specific Shops with their
prices and quantities at given Shops? So, that all these can be
conveniently iterated?

I need to render a page with a list of Items and their Prices and
Quantities at specific shops. There is a template for displaying Item
there (with all it’s subproperties – prices etc). So, it would be the most convenient to pass just one object to
this template and iterate it and it’s subobjects (if any) there.

  • 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-15T19:19:50+00:00Added an answer on May 15, 2026 at 7:19 pm

    I struggle with this kind of scenario in Doctrine, as well. Rails had spoiled me with their has_many :through => relationship which makes this sort of thing trivial.

    You are correct, you do need three entities: Shops, Items, ItemsAtShops using dual ManyToOne relationships.

    I would assume that ItemsAtShop would look like:

    class ItemsAtShop 
    {        
       private $shop;
       private $items;
       private $quantity;
    }
    

    As far a querying goes, you’ll need to rock the joins:

    $queryBulder->select('ias')
                ->from(ItemsAtShop, 'ias')
                ->leftJoin('ias.Item', 'i')
                ->leftJoin('ias.Shop', 's')
                ->where('s.id = :shop_id')
                ->andWhere('i.price <= :my_price')
                ->orderBy('i.price', 'DESC');
    

    Remember, when using DQL, you’re usually querying entire Entity objects, which will fetch their relationships on their own. This should result in a collection of ItemsAtShop you can iterate over.

    I might take some fidgeting to figure out the correct query. I’ll often start with a SQL query I know works, and translate it into DQL.

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

Sidebar

Related Questions

I have following using Jquery and somehow I can resize it the right bottom
i'm making a client for pop3 and somehow i can't figure out how to
I am implementing iCarousel in my app but somehow can't figure out which view
I'm trying to figure out if there's a way I can somehow notify a
This sure seems like a simple error to fix. However, I somehow can't figure
I'm busy implementing the wurfl api using PHP, but somehow just can't seem to
Can I somehow disable ListView items navigation through keyboard (arrow keys), and leave navigation
I can't figure out how (or if it's at all possible) to use the
Somehow I can't get the iframe mode to work in the following code The
This sounds like a trivial question but somehow I can't seem to figure it

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.