Re: [fw-general] Doctrine Counter Behavior

2010-01-13 Thread drm

bparise wrote:

Ideally, these could all be under 1 service class... this way the models
don't have anything defined in them other than the ORM stuff.

ForumService::changeTopic(Post $post, Topic $newTopic)
ForumService::savePost(Post $post)
ForumService::deletePost(Post $post)
ForumService::sendEmailNotifications(Topic $topic)

What are your thoughts about this?  I feel its a bit of redundancy since
most of these methods are only going to be called within 1 place anyways.

I'm not sure if this is the info you wanted, but here goes:

I think you should think about whether your application logic should be 
worried about when and how these things need to be done. I don't really 
think so. The application is only adding a post, whether your model 
decides to precache the postcount per topic is up to the model. So you'd 
use a service layer to tell your model to add a post, and the model 
handles the rest.


In the case of the post count, it makes sense to think about where you'd 
let your application ask the model how many posts a topic has. Would you 
let the service layer, or even the application layer, wonder about where 
to get this info? The answer is no. You simply tell your model get me 
these topics, and I want to know the post count per topic. So, if the 
application or service layer don't know how to get this info, why should 
they know how to store it in the first place?


One more piece of food-for-thought:
Let's say you didn't precache this info, but used a JOIN with a COUNT() 
whenever you read topics from the database. Now you encounter problems 
with performance and you decide to cache this info. In what part of your 
application would you want to make changes? The obvious hint is that 
we're talking about SQL here.


Also note that Doctrine 1.x's Active Record pattern isn't really a good 
practice for separating business model logic and persistence logic. 
These two are intertwined in such a pattern, and it would (imho) 
actually overcomplicate things trying to separate these more than 
absolutely necessary.


HTH
drm / Gerard


Re: [fw-general] Doctrine Counter Behavior

2010-01-12 Thread bparise


monk.e.boy wrote:
 
 
 
 bparise wrote:
 
 
 For some reason I don't really like imposing this dependency on the Post
 side.  Maybe I should decouple it and create a Topic::savePost(Post) that
 takes care of this?
 
 
 
 BINGO! ;)
 

Maybe this question is part of a larger design pattern.  I really like the
idea of having all functionality encapsulated in 1 class, but then again I
don't want to have to repeat myself.

For instance...

Topic::savePost(Post)
Topic::deletePost(Post)
Post::changetTopic(Topic)
Topic::sendEmailNotifications()

Ideally, these could all be under 1 service class... this way the models
don't have anything defined in them other than the ORM stuff.

ForumService::changeTopic(Post $post, Topic $newTopic)
ForumService::savePost(Post $post)
ForumService::deletePost(Post $post)
ForumService::sendEmailNotifications(Topic $topic)

What are your thoughts about this?  I feel its a bit of redundancy since
most of these methods are only going to be called within 1 place anyways.


-- 
View this message in context: 
http://n4.nabble.com/Doctrine-Counter-Behavior-tp1010418p1012383.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Re: [fw-general] Doctrine Counter Behavior

2010-01-10 Thread monk.e.boy



bparise wrote:
 
 
 For some reason I don't really like imposing this dependency on the Post
 side.  Maybe I should decouple it and create a Topic::savePost(Post) that
 takes care of this?
 
 

BINGO! ;)
-- 
View this message in context: 
http://n4.nabble.com/Doctrine-Counter-Behavior-tp1010418p1010857.html
Sent from the Zend Framework mailing list archive at Nabble.com.


[fw-general] Doctrine Counter Behavior

2010-01-09 Thread bparise

I was wondering what's the best way to implement a counter sort of behavior
(doesn't need to actually be a doctrine behavior, just the concept)..

I have 2 models... Topics and Posts
In topics there is a column Topics.post_count that I want to keep
(obviously) the number of posts the topic has.

Whats the best way to do this?

Option A.
Post::postInsert() ... Increment Topics.postCount ++;
Post::postDelete() ... Decrement Topics.post_count --;

Option B.
Post::postSave() ... Call Topic-updatePostCount() which does a simple
SELECT COUNT(*) on posts




-- 
View this message in context: 
http://n4.nabble.com/Doctrine-Counter-Behavior-tp1010418p1010418.html
Sent from the Zend Framework mailing list archive at Nabble.com.