tag:blogger.com,1999:blog-36547168.post9185327870243868793..comments2023-11-25T11:00:42.257+01:00Comments on Invisible to the eye: Repositories in DoctrineGiorgiohttp://www.blogger.com/profile/03558287012747987157noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-36547168.post-29155129690889913642011-01-22T12:51:35.115+01:002011-01-22T12:51:35.115+01:00Here's how to use DQL for pagination:
http://w...Here's how to use DQL for pagination:<br />http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html#first-and-max-result-items-dql-query-onlyGiorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-89321678425378833082011-01-22T11:19:33.491+01:002011-01-22T11:19:33.491+01:00Hi again,
I am quite a noob :) Could you give me a...Hi again,<br />I am quite a noob :) Could you give me a short example please?<br /><br />Thanks<br />BillAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-36547168.post-2773104664234424012011-01-21T10:56:44.784+01:002011-01-21T10:56:44.784+01:00You'll need the EntityManager to execute a que...You'll need the EntityManager to execute a query, so it's best seen as a method on an external Repository or DAO more than on the Article or on another Entity.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-86752732289702141502011-01-20T22:04:04.777+01:002011-01-20T22:04:04.777+01:00Thanks for the reply.
I thought collection would b...Thanks for the reply.<br />I thought collection would be lazy loaded via entities proxy object. But how would you implement the query here? $article->comment will retreive all comments, right? So do we implement something like<br />$article->getComments($from, $count)<br />and then write the dql in article objects getComments method?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-36547168.post-2961076470804680912011-01-20T18:13:34.981+01:002011-01-20T18:13:34.981+01:00As far as I know, the collection is lazy loaded (b...As far as I know, the collection is lazy loaded (but in a single shot), so you'll get the 1 million comments only if you call a method on the Collection object. We usually do pagination via queries - it's very simple to write a query in DQL to retrieve the content of a collection, especially if you already have the Entity.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-69889199357200483522011-01-20T17:52:39.043+01:002011-01-20T17:52:39.043+01:00Hi,
I have a question. I am looking at CmsArticle ...Hi,<br />I have a question. I am looking at CmsArticle entity here<br />https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/Models/CMS/CmsArticle.php<br /><br />So CmsArticle can have many CmsComments. Let's say a article has 1 million comments, when we do $aArticle->getComments() (which is not implemented on the github) we will load all 1 million comments.<br /><br />is there a way to use some kind of limit/offset or pagination within doctrine entities ?<br /><br />Thanks<br />BillAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-36547168.post-15048610257264838672010-05-15T20:26:32.328+02:002010-05-15T20:26:32.328+02:00No, in general you should mock only type you creat...No, in general you should mock only type you create. You can *integration* test your repository by passing it an EntityManager which works with sqlite (lightweight) instead of MySQL or your production database of choice.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-8329530302158461682010-05-15T10:23:12.205+02:002010-05-15T10:23:12.205+02:00How would I unit test my custom implementation in ...How would I unit test my custom implementation in a repository, should I mock the entity manager?Unknownhttps://www.blogger.com/profile/16555661418154584127noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-37658838702700948882010-02-18T11:13:05.917+01:002010-02-18T11:13:05.917+01:00Usually your repository has $this->_em as a fie...Usually your repository has $this->_em as a field reference, passing it the entity to persist when an add() method is called. The Api of the repository is similar to a collection one, but its concrete implementation puts to and gets from the EntityMnager instead of to and from an array.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-1499815339357379842010-02-18T03:02:17.963+01:002010-02-18T03:02:17.963+01:00Hi, I'm new to Doctrine 2 but I also find it u...Hi, I'm new to Doctrine 2 but I also find it useful on implementing with Repository pattern. However I'm lil' bit confused what should be the entity that will going to pass to $em->persist() to make the entity persist, is it the Entity Domain Object from the domain layer of DDD? If that is, then how could it be map to a Database table? Thanks<br /><br />- juan.delacruzweb@yahoo.comJuannoreply@blogger.comtag:blogger.com,1999:blog-36547168.post-42982075280000073062010-02-18T02:20:34.106+01:002010-02-18T02:20:34.106+01:00Thanks giorgio, that helpsThanks giorgio, that helpsJeboyhttps://www.blogger.com/profile/08822744377373579591noreply@blogger.com