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 two models, Article and Post that both inherit from a base model
I have a few models that need to have custom find conditions placed on
Say that I have two models- Users and Accounts. Each account can have at
I have a set of data that models a hierarchy of categories. A root
I have a models A and B , that are like this: class A(models.Model):
I have two models, Room and Image . Image is a generic model that
So I have a User model that :has_many other models like Documents, Videos, Posts
I have an existing app that has many, many models. I'd like to log
Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
Specifically, I have a model that has a field like this pub_date = models.DateField(date

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.