NH will not manage that for you. But you can use lazy="extra" as a way to
manage that
On Wed, Oct 22, 2008 at 10:49 PM, jonnii <[EMAIL PROTECTED]> wrote:
>
> It's a way of keeping the record count of an association in the parent
> table.
>
> So if you had:
>
> posts
> - id
> - title
> - body
> - comment_count
>
> Comments
> - id
> - body
> - post_id
>
> Then the comment count field for a post would contain the number of
> posts. This means that if you did something like
>
> Post p = postsRepository.Find(3);
> Console.WriteLine(p.Count);
>
> You wouldn't hit the database because the count on the association
> would be loaded from the posts table.
>
> In AR there are hooks on the associations that increment and decrement
> the counter cache if it's available.
>
> Does that make sense?
>
> Here's some more from AR's documentation:
>
> # :counter_cache - caches the number of belonging objects on the
> associate class through the use of increment_counter and
> decrement_counter. The counter cache is incremented when an object of
> this class is created and decremented when it's destroyed. This
> requires that a column named #{table_name}_count (such as
> comments_count for a belonging Comment class) is used on the associate
> class (such as a Post class). You can also specify a custom counter
> cache column by providing a column name instead of a true/false value
> to this option (e.g., :counter_cache => :my_custom_counter.) Note:
> Specifying a counter_cache will add it to that model's list of
> readonly attributes using attr_readonly.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---