{"issue":{"created_at":"2011-12-03T18:36:30Z","state":"closed","updated_at":"2011-12-07T23:43:15Z","comments":2,"user":{"gravatar_id":"5ff08d90b55f2295ec80ed63585aee7c","id":283700,"url":"https://api.github.com/users/gossi","login":"gossi","avatar_url":"https://secure.gravatar.com/avatar/5ff08d90b55f2295ec80ed63585aee7c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"Lets assume, in my schema, I have a table `Book` and therefore a query called `BookQuery`. So, if I extend my `Book` class manually, like this one:\r\n\r\n    class Drama extends Book\r\n\r\nI have no chance to query for `Drama`. I could extend a `DramaQuery` class but that query would return a `Book` instance:\r\n\r\n    $r = DramaQuery::create()->findOne();\r\n    var_dump($r); // Book\r\n\r\nLooking for some API that modify the returned instance from *Query find methods to whatever I want here.\r\n\r\nThanks","assignee":null,"id":2438525,"number":215,"labels":[],"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"title":"Query for own extended classes","html_url":"https://github.com/propelorm/Propel/issues/215","closed_at":"2011-12-07T23:43:15Z","url":"https://api.github.com/repos/propelorm/Propel/issues/215","milestone":null},"action":"created","comment":{"created_at":"2011-12-07T23:43:15Z","updated_at":"2011-12-07T23:43:15Z","user":{"gravatar_id":"8ad62a25686796c42fedbe3ddedce1f1","id":99944,"url":"https://api.github.com/users/fzaninotto","login":"fzaninotto","avatar_url":"https://secure.gravatar.com/avatar/8ad62a25686796c42fedbe3ddedce1f1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"Hi Thomas,\r\n\r\nI think that overriding `BaseBookQuery::__construct()` and `BaseBookQuery::create() `in your `DramaQuery` class should do the trick. \r\n\r\nSomething like:\r\n\r\n```php\r\n<?php\r\nclass DramaQuery extends BookQuery\r\n{\r\n    /**\r\n     * Initializes internal state of BaseBookQuery object.\r\n     *\r\n     * @param     string $dbName The dabase name\r\n     * @param     string $modelName The phpName of a model, e.g. 'Book'\r\n     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'\r\n     */\r\n    public function __construct($dbName = 'bookstore', $modelName = 'Drama', $modelAlias = null)\r\n    {\r\n        parent::__construct($dbName, $modelName, $modelAlias);\r\n    }\r\n\r\n    /**\r\n     * Returns a new BookQuery object.\r\n     *\r\n     * @param     string $modelAlias The alias of a model in the query\r\n     * @param     Criteria $criteria Optional Criteria to build the query from\r\n     *\r\n     * @return    BookQuery\r\n     */\r\n    static public function create($modelAlias = null, $criteria = null)\r\n    {\r\n        if ($criteria instanceof DramaQuery) {\r\n            return $criteria;\r\n        }\r\n        $query = new DramaQuery();\r\n        if (null !== $modelAlias) {\r\n            $query->setModelAlias($modelAlias);\r\n        }\r\n        if ($criteria instanceof Criteria) {\r\n            $query->mergeWith($criteria);\r\n        }\r\n\r\n        return $query;\r\n    }\r\n}\r\n```\r\n\r\nNotice I just replaced the three occurrences of `Book` in the generated code by `Drama`.","id":3055553,"url":"https://api.github.com/repos/propelorm/Propel/issues/comments/3055553"}}