User: xtoff
Date: 2010/01/09 07:50 AM

Added:
 /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
  FetchTestCase.cs

Modified:
 /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
  Castle.ActiveRecord.Tests-vs2008.csproj
 /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/GenericModel/
  Blog.cs
 /ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/
  ActiveRecordBase.Generic.cs, ActiveRecordBase.cs

Log:
 - fixed AR-ISSUE-270 - "Setting Fetch = FetchEnum.Join on a HasMany property 
returns duplicate records".
 Fix works only for no-parameters overload of FindAll.
 For all other overloads, it is the responsibility of the caller to pass 
criteria with appropriate IResultTransformer.

File Changes:

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/
=============================================================

File [modified]: Castle.ActiveRecord.Tests-vs2008.csproj
Delta lines: +62 -0
===================================================================

--- ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/FetchTestCase.cs           
                (rev 0)
+++ ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/FetchTestCase.cs   
2010-01-09 14:50:47 UTC (rev 6608)
@@ -0,0 +1,63 @@
+namespace Castle.ActiveRecord.Tests
+{
+       using NUnit.Framework;
+
+       using Castle.ActiveRecord.Tests.Model.GenericModel;
+
+       [TestFixture]
+       public class FetchTestCase : AbstractActiveRecordTest
+       {
+               public override void Init()
+               {
+                       base.Init();
+
+                       ActiveRecordStarter.Initialize(GetConfigSource(),
+                               typeof(Blog),
+                               typeof(Post),
+                               typeof(Company),
+                               typeof(Award),
+                               typeof(Employee),
+                               typeof(Person));
+
+                       Recreate();
+
+                       Post.DeleteAll();
+                       Blog.DeleteAll();
+                       Company.DeleteAll();
+                       Award.DeleteAll();
+                       Employee.DeleteAll();
+               }
+
+
+               [Test]
+               public void 
FetchEnum_Join_on_a_HasMany_property_should_not_return_duplicate_records()
+               {
+                       Blog[] blogs = Blog.FindAll();
+
+                       Assert.IsNotNull(blogs);
+                       Assert.AreEqual(0, blogs.Length);
+
+                       var blog = new Blog { Name = "Test blog", Author = 
"Eric Bowen" };
+
+                       blog.Save();
+
+                       var post = new Post(blog, "Post1", "Content1", 
"Category1");
+                       post.Save();
+
+                       blog.Posts.Add(post);
+
+                       var post2 = new Post(blog, "Post2", "Content2", 
"Category2");
+                       post2.Save();
+
+                       blog.Posts.Add(post2);
+
+                       blog.Save();
+
+                       blogs = Blog.FindAll();
+
+                       Assert.IsNotNull(blogs);
+                       Assert.AreEqual(1, blogs.Length);
+
+               }
+       }

File [added]: FetchTestCase.cs
Delta lines: +18 -50
===================================================================

--- ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/GenericModel/Blog.cs 
2010-01-09 14:16:26 UTC (rev 6607)
+++ ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/GenericModel/Blog.cs 
2010-01-09 14:50:47 UTC (rev 6608)
@@ -14,75 +14,43 @@
 
 namespace Castle.ActiveRecord.Tests.Model.GenericModel
 {
-       using System;
        using System.Collections;
        using System.Collections.Generic;
 
        using NHibernate;
 
-    using Castle.ActiveRecord;
+       using Castle.ActiveRecord;
        using Castle.ActiveRecord.Framework;
 
 
        [ActiveRecord("BlogTable")]
        public class Blog : ActiveRecordBase<Blog>
        {
-               private int _id;
-               private String _name;
-               private String _author;
-               private IList<Post> _posts = new List<Post>();
-               private IList _publishedposts;
-               private IList _unpublishedposts;
-               private IList _recentposts;
-
-               [PrimaryKey]
-               public int Id
+               public Blog()
                {
-                       get { return _id; }
-                       set { _id = value; }
+                       Posts = new List<Post>();
                }
 
+               [PrimaryKey]
+               public int Id { get; set; }
+
                [Property]
-               public String Name
-               {
-                       get { return _name; }
-                       set { _name = value; }
-               }
+               public string Name { get; set; }
 
                [Property]
-               public String Author
-               {
-                       get { return _author; }
-                       set { _author = value; }
-               }
+               public string Author { get; set; }
 
-               [HasMany(Table="Posts", ColumnKey="blogid")]
-               public IList<Post> Posts
-               {
-                       get { return _posts; }
-                       set { _posts = value; }
-               }
+               [HasMany(Table = "Posts", Fetch = FetchEnum.Join, ColumnKey = 
"blogid")]
+               public IList<Post> Posts { get; set; }
 
-               [HasMany(typeof (Post), Table="Posts", ColumnKey="blogid", 
Where="published = 1")]
-               public IList PublishedPosts
-               {
-                       get { return _publishedposts; }
-                       set { _publishedposts = value; }
-               }
+               [HasMany(typeof(Post), Table = "Posts", ColumnKey = "blogid", 
Where = "published = 1")]
+               public IList PublishedPosts { get; set; }
 
-               [HasMany(typeof (Post), Table="Posts", ColumnKey="blogid", 
Where="published = 0")]
-               public IList UnPublishedPosts
-               {
-                       get { return _unpublishedposts; }
-                       set { _unpublishedposts = value; }
-               }
+               [HasMany(typeof(Post), Table = "Posts", ColumnKey = "blogid", 
Where = "published = 0")]
+               public IList UnPublishedPosts { get; set; }
 
-               [HasMany(typeof (Post), Table="Posts", ColumnKey="blogid", 
OrderBy="created desc")]
-               public IList RecentPosts
-               {
-                       get { return _recentposts; }
-                       set { _recentposts = value; }
-               }
+               [HasMany(typeof(Post), Table = "Posts", ColumnKey = "blogid", 
OrderBy = "created desc")]
+               public IList RecentPosts { get; set; }
 
                public void CustomAction()
                {
@@ -99,7 +67,7 @@
 
                internal static ISessionFactoryHolder Holder
                {
-            get { return ActiveRecordMediator<Blog>.GetSessionFactoryHolder(); 
}
+                       get { return 
ActiveRecordMediator<Blog>.GetSessionFactoryHolder(); }
                }
-    }
+       }

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/
=================================================================

File [modified]: ActiveRecordBase.Generic.cs
Delta lines: +5 -1
===================================================================

--- ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/ActiveRecordBase.cs    
2010-01-09 14:16:26 UTC (rev 6607)
+++ ActiveRecord/trunk/src/Castle.ActiveRecord/Framework/ActiveRecordBase.cs    
2010-01-09 14:50:47 UTC (rev 6608)
@@ -986,7 +986,11 @@
                /// <returns>The <see cref="Array"/> of results</returns>
                protected internal static Array FindAll(Type targetType)
                {
-                       return FindAll(targetType, (Order[])null);
+                       // to ensure we have no duplicates when an outer join 
is being used.
+                       // NOTE: perhaps we could detect such scenario and do 
it only then?
+                       var criteria = DetachedCriteria.For(targetType)
+                               
.SetResultTransformer(CriteriaSpecification.DistinctRootEntity);
+                       return FindAll(targetType, criteria, null);
                }
 

File [modified]: ActiveRecordBase.cs
Delta lines: +1 -0
===================================================================

--- 
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
    2010-01-09 14:16:26 UTC (rev 6607)
+++ 
ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Castle.ActiveRecord.Tests-vs2008.csproj
    2010-01-09 14:50:47 UTC (rev 6608)
@@ -331,6 +331,7 @@
     <Compile Include="Config\ConfigureTests.cs" />
     <Compile Include="Config\StorageConfigurationTests.cs" />
     <Compile Include="DefaultConfigurationsTestCase.cs" />
+    <Compile Include="FetchTestCase.cs" />
     <Compile Include="Model\CompositeUserType\BadProduct.cs" />
     <Compile Include="Model\ProductWithGuid.cs" />

Directory: /ActiveRecord/trunk/src/Castle.ActiveRecord.Tests/Model/GenericModel/
================================================================================

File [modified]: Blog.cs
Delta lines: +0 -0
===================================================================

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" 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/castle-project-commits?hl=en.


Reply via email to