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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:01:39+00:00 2026-05-15T16:01:39+00:00

In doctrine, is it possible to add a WHERE clause when fetching a property

  • 0

In doctrine, is it possible to add a WHERE clause when fetching a property of an object that corresponds to a relationship?

In terms of concept, let’s say I want to retrieve only the first 3 blog posts made in the last 5 days. My “blog” object has a “posts” property which is defined as a relationship.

Update…

As some people are having some difficulties understanding what I mean by a relationship:

class Blog extends Doctrine_Record {

       ...

       public function setUp() {

            $this->hasMany("Note as Posts", array(
                "local" => "blog_name",
                "foreign" => "post_id",
                "refClass" => "BlogPost"
            ));

       }
}

As you can see, this is an explicit relationship as supported by doctrine. When I query using it:

     $instanceOfBlog->Posts...........

I’d like to know if I can add additional clauses at that 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-15T16:01:40+00:00Added an answer on May 15, 2026 at 4:01 pm

    Not sure I follow you, but if it’s what I think then in your BlogTable class:

    public function getRecentPosts()
    {
      $qry = self::createQuery("b")
        ->innerJoin("b.Posts p")
        ->where("p.created_at > ?", date("Y-m-d H:i:s", strtotime("-5 days")))
        ->orderBy("p.created_at DESC")
        ->limit(3);
    
      $results = $qry->execute();
    }
    

    Is that what you were after? This is based on the created_at field in the Posts object, and assumes a relationship is defined between the Blog and Posts tables.

    I may have misunderstood your question entirely however 🙂

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

Sidebar

Related Questions

Is it possible to use OR statement in Doctrine findBy() method? I know that
Is it possible to add behaviors (eg. actAs Timestampable) in a doctrine migration to
In PHP Doctrine, is it possible to create one migration class that creates a
You may access the (let's say) Doctrine service inside the controller, using: $d =
is possible overwriting a Doctrine model in Symfony? I'm trying no change a notnull
Is it possible to craft a wildcard WHERE query with Doctrine, like so: ->where('this_field
Doctrine version 2.1 i am persisting a lot of objects, that is why I
With doctrine syntax using postgres as database, is it possible to generate a query
I want to count all the records of a table using Doctrine ORM and
I have a Doctrine_Collection object that was created with code that looks something like.

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.