datamapper

Doctrine2 Best Practice, Should Entities use Services?

ぃ、小莉子 提交于 2019-11-30 10:22:08
I asked a similar question a while back: Using the Data Mapper Pattern, Should the Entities (Domain Objects) know about the Mapper? However, it was generic and I'm really interested in how to accomplish a few things with Doctrine2 specifically . Here's a simple example model: Each Thing can have a Vote from a User , a User may cast more than one Vote but only the last Vote counts. Because other data ( Msssage , etc) is related to the Vote , when the second Vote is placed the original Vote can't just be updated, it needs to be replaced. Currently Thing has this function: public function addVote

What exactly is the difference between a data mapper and a repository?

亡梦爱人 提交于 2019-11-30 00:26:20
Well I've been trying to find out the difference between data mapper and repository, but up to now I still have not. It seems to me that the expert programmer said "Repository is another layer of abstraction over the mapping layer where query construction code is concentrated". It seems understandable but is still somewhat very abstract. I read this article on stackoverflow before, and it just made me even more confused: How is the Data Mapper pattern different from the Repository Pattern? I guess what I need are simple explanations and concrete/practical examples on how the two patterns

Using the Data Mapper Pattern, Should the Entities (Domain Objects) know about the Mapper?

假如想象 提交于 2019-11-29 23:19:37
I'm working with Doctrine2 for the first time, but I think this question is generic enough to not be dependent on a specific ORM. Should the entities in a Data Mapper pattern be aware - and use - the Mapper ? I have a few specific examples, but they all seem to boil down to the same general question. If I'm dealing with data from an external source - for example a User has many Messages - and the external source simply provides the latest few entities (like an RSS feed), how can $user->addMessage($message) check for duplicates unless it either is aware of the Mapper, or it 'searches' through

How do I truncate tables properly?

China☆狼群 提交于 2019-11-29 20:53:16
I'm using datamapper with ruby to store data to certain tables. Several of the tables have very large amounts of information and I want to clear them out when the user 'rebuilds database' (it basically deletes everything and re-calculates data). I originally tried Forum.all.destroy and did it for all the different tables, but I noticed some of them just werent deleted from within phpmyadmin. i can only imagine its because of foreign keys. Although I really dont know because my other table which foreing keys was successfully deleted. Not to mention, id rather just 'zero' it out anyway so the

Doctrine2 Best Practice, Should Entities use Services?

爱⌒轻易说出口 提交于 2019-11-29 16:19:48
问题 I asked a similar question a while back: Using the Data Mapper Pattern, Should the Entities (Domain Objects) know about the Mapper? However, it was generic and I'm really interested in how to accomplish a few things with Doctrine2 specifically . Here's a simple example model: Each Thing can have a Vote from a User , a User may cast more than one Vote but only the last Vote counts. Because other data ( Msssage , etc) is related to the Vote , when the second Vote is placed the original Vote can

Using the Data Mapper Pattern, Should the Entities (Domain Objects) know about the Mapper?

落花浮王杯 提交于 2019-11-28 21:14:19
问题 I'm working with Doctrine2 for the first time, but I think this question is generic enough to not be dependent on a specific ORM. Should the entities in a Data Mapper pattern be aware - and use - the Mapper ? I have a few specific examples, but they all seem to boil down to the same general question. If I'm dealing with data from an external source - for example a User has many Messages - and the external source simply provides the latest few entities (like an RSS feed), how can $user-

In Doctrine 2 can the Fetch Mode (Eager/Lazy etc.) be changed at runtime?

旧巷老猫 提交于 2019-11-28 19:23:00
I have entities which I would like to eagerly load , and on other ocassions lazy (or even extra lazy) load. My mappings have no fetch mode declared in my YAML- so they use the default (lazy loading). Currently the only way to eagerly load is to by constructing the DQL manually - and I need to update this every time I add a new entity. Ideally I would just load the root entity and the force eager loading all the associated objects. Is there any way I can do this? If not why (is there a reason beyond it being an unimplemented feature)? If you want to use built-in repository methods (find(),

Data Mapper and Relationships: Implementation strategies?

假装没事ソ 提交于 2019-11-28 17:12:25
问题 I've almost finished my Data Mapper, but now I'm at the point where it comes to relationships. I will try to illustrate my ideas here. I wasn't able to find good articles / informations on this topic, so maybe I'm re-inventing the wheel (for sure I am, I could just use a big framework - but I want to learn by doing it). 1:1 Relationships First, lets look at 1:1 relationships. In general, when we've got an domain class called "Company" and one called "Address", our Company class will have

How do I truncate tables properly?

 ̄綄美尐妖づ 提交于 2019-11-28 17:03:09
问题 I'm using datamapper with ruby to store data to certain tables. Several of the tables have very large amounts of information and I want to clear them out when the user 'rebuilds database' (it basically deletes everything and re-calculates data). I originally tried Forum.all.destroy and did it for all the different tables, but I noticed some of them just werent deleted from within phpmyadmin. i can only imagine its because of foreign keys. Although I really dont know because my other table

How to find records by month Datamapper

南楼画角 提交于 2019-11-28 12:02:49
问题 In my project I need to have ability ti add reports. Adding a report user can choose date for placing his report. (not created_at) I save this data in "Date":DataTime - format column(2012-03-24T00:00:00+00:00) User selects date from datepicker and than i parse it with DateTime.parse(2012-03-24) and than save to DB. Than user via datepicker selects a month. How can I correctly perform a query to find all records for perticular month? Is there any method to find by month? 回答1: No. You should