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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:07:05+00:00 2026-05-17T19:07:05+00:00

I have models that extend Doctrine_Record, and are directly mapped to one specific record

  • 0

I have models that extend Doctrine_Record, and are directly mapped to one specific record from the database (that is, one record with given a given id, hardcoded statically in the class).

Now, I want the specific record class to initialize itself as if Doctrine_Query would. So, this would be the normal procedure:

$query = new Doctrine_Query();
$model = $query->from('Model o')->where('id = ?', 123)->fetchOne();

I would like to do something like this

$model = new Model();

And in the Model:

const ID = 123;

//note that __construct() is used by Doctrine_Record so we need construct() without the __
public function construct()
{
    $this->id = self::ID;
    //what here??
    $this->initialize('?????');
}

So for clarity’s sake: I would like the object to be exactly the same as if it would be received from a query (same state, same attributes and relations and such).

Any help would be greatly appreciated: thank you.

  • 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-17T19:07:06+00:00Added an answer on May 17, 2026 at 7:07 pm

    The first thing I need to say is I’d put the constant in the class. So like this:

    class Application_Model_Person
    {
        const ID = 1234;
    }
    

    Then, a Doctrine method like Doctrine_Record::fetchOne() is always returning a (new) instance of the model and never merges the data with the record you’re calling fetchOne() to. Doctrine is nevertheless able to merge a retreived record with another class, so it rather simple to do:

    class Application_Model_Person extends Doctrine_Record_Abstract
    {
        const ID = 1234;
    
        public function __construct($table = null, $isNewEntry = false)
        {
            // Calling Doctrine_Record::__construct
            parent::__construct($table, $isNewEntry);
    
            // Fetch the record from database with the id self::ID
            $record = $this->getTable()->fetchOne(self::ID);
            $this->merge($record);
        }
    }
    

    Then you’re able to do:

    $model = new Application_Model_Person;
    echo $model->id; // 1234
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base model that I extend from. In it, I have defined
I have three models that are coming together to create one view model and
I have four models that are related to one another, the way I have
I have some types that extend a common type, and these are my models.
I have a module with two models that extend Zend_Db_Table_Abstract: class Departments_Model_Subpages extends Zend_Db_Table_Abstract
I have several models that need to call a method that takes a particular
I have 2 models that have a many-to-many association(an Event has many Products and
I have three models that I'm trying to setup: Location/Venues, Categories, and Neighborhoods. A
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I have some models that are laid out like so (with a lot more

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.