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

  • Home
  • SEARCH
  • 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 3848990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:47:08+00:00 2026-05-19T16:47:08+00:00

Is it possible to set a constraint in a Doctrine model, so that all

  • 0

Is it possible to set a constraint in a Doctrine model, so that all queries using that model include this requirement? For example, if I have a Car model and I want to ensure that all results retrieved using the model have active = 1 set in the database. I could define this in each individual query, but it seems like there’s probably a better way.

Cheers!

  • 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-19T16:47:09+00:00Added an answer on May 19, 2026 at 4:47 pm

    I would take advantage of their amazing pre and post hooks inside the model.

    Example:

    class Model_Car extends Model_Base_Car
    {
        public function preDqlSelect(Doctrine_Event $event)
        {
            $event->getQuery()->addWhere("active = ?", 1);
        }
    }
    

    Although I did not test this, it should work. I have used the pre and post hooks a lot to make my life easier in the past. For instance, I had a model that wanted to save the REMOTE_ADDR on each insert and update, so I did the following to make my life easier:

    class Model_Example extends Model_Base_Example
    {
        public function preInsert(Doctrine_Event $event)
        {
            $this->created_ip = $this->_getRemoteIp();
        }
    
        public function preUpdate(Doctrine_Event $event)
        {
            $this->updated_ip = $this->_getRemoteIp();
        }
    
        protected function _getRemoteIp()
        {
            return ip2long($_SERVER['REMOTE_ADDR']);
        }
    }
    

    hope this helps!

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

Sidebar

Related Questions

Is it possible to set code behind a resource dictionary in WPF. For example
Is it possible to set the data in a ContentPlaceHolder through code? This is
Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up
I am using phpMyAdmin. In order to set up a foreign key constraint with
I have n elements that need to be partitioned into x sets, each set
I have a java.sql.ResultSet object that I need to update. However the result set
I wish to drop all the constraints of tables I have. Since this is
Is possible to set an image as an iPhone application unique icon in code
Is it possible to set the cursor to 'wait' on the entire html page
Is it possible to set the position of the tabs to be at the

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.