Kooboo / CMS

Old Kooboo CMS, Use Kooboo/Kooboo instead.
http://www.kooboo.com
Other
337 stars 222 forks source link

Bug "scope" using WhereCategory and OrElseExpression #314

Open Godoy opened 9 years ago

Godoy commented 9 years ago

Hi all, I have 2 content types: News and Category And the following relationship in content folder News: screen shot 2015-03-05 at 11 42 02 am

When I do some like:

    var news = ContentHelper.TextFolder("News").CreateQuery()
        .Where(new OrElseExpression(
                new WhereEqualsExpression("Published", true), 
                new WhereEqualsExpression("UserKey", "testUserKey")
            )
        )
        .ToList();

Correct SQL generated:

SELECT * FROM [teste.News] content WHERE 
(
    (
        (
            ([Published] = @Param0)
        ) 
        OR 
        (
            ([UserKey] = @Param1)
        )
    )
) 
AND 
FolderName=@Param2  
ORDER BY Id DESC',N'@Param0 bit,@Param1 nvarchar(11),@Param2 nvarchar(4)',@Param0=1,@Param1=N'testUserKey',@Param2=N'News'

But when I try with category:

    var catExample = ContentHelper.TextFolder("Categories").CreateQuery().WhereEquals("UserKey", "cat-a");

    var news = ContentHelper.TextFolder("News").CreateQuery()
        .Where(new OrElseExpression(
                new WhereEqualsExpression("Published", true),
                new WhereCategoryExpression(catExample)
            )
        )
        .ToList();

Generated code:

SELECT * FROM [teste.News] content WHERE 
(
    (
        (
            ([Published] = @Param0)
        ) 
        OR 
        (1=1)
    )
) 
AND 
FolderName=@Param1 
AND EXISTS(
    SELECT *, ContentCategory.CategoryUUID 
        FROM [teste.__ContentCategory] ContentCategory,
            (SELECT * FROM [teste.Category] content WHERE ([UserKey] = @Param2) AND FolderName=@Param3 )category
        WHERE content.UUID = ContentCategory.UUID AND ContentCategory.CategoryUUID = category.UUID 
)  
ORDER BY Id DESC',N'@Param0 bit,@Param1 nvarchar(4),@Param2 nvarchar(5),@Param3 nvarchar(10)',@Param0=1,@Param1=N'News',@Param2=N'cat-a',@Param3=N'Categories'

The "Category" query is out of the "Or" scope and the logic of query is incorrect. Somebody help me?

I'm using SQL Server provider for Content Provider.

Thx