newbe question, manytomany and filter. selfservicing

Posts   
 
    
hootie
User
Posts: 6
Joined: 24-Aug-2006
# Posted on: 11-Sep-2006 18:10:06   

I have a collection with directories and subdirectories. I need to list directories that the current user are allowed to see.

'directories:


Dim group As GroupEntity
Dim directories As DirectoryCollection
Dim allDirectories As New DirectoryCollection
For Each group In currentUser.GroupCollectionViaUsers
      directories = New DirectoryCollection
      directories.GetMultiManyToManyUsingGroupCollectionViaAttributes(group)
      allDirectories.AddRange(directories)
Next
Repeater1.DataSource = allDirectories
Repeater1.DataBind()

now, the result of this is that all directories is returned. even all sub directories. To solve this I tried the following code which returns the parent directories. :


Dim selectFilter As IPredicateExpression = New PredicateExpression(New FieldCompareNullPredicate(DirectoryFields.ParentId))
directories.GetMulti(selectFilter)
Repeater1.DataSource = directories
Repeater1.DataBind()

the problem here is that directories that the current user are not allowed to see are returned.

How can I combine these two?

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 18:55:06   

Hi,

unfortunately, the GetMultiManyToManyUsingGroupCollectionViaAttributes method that you call does not have an overload, which accepts an additional filter.

But this is also because it's aimed at being a convenient shortcut. If you browse its definition and the inner calls, you'll see that it ends up calling the GetMulti() method which gets the corresponding filter as an argument.

So I'd suggest that you combine the "group" filtering that you can see in the GetMultiUsingGroupCollectionViaAttributes() from the Dao class with your additional filter and make direct use of the getmulti method.

Cheers

hootie
User
Posts: 6
Joined: 24-Aug-2006
# Posted on: 11-Sep-2006 21:55:55   

Jessynoo wrote:

So I'd suggest that you combine the "group" filtering that you can see in the GetMultiUsingGroupCollectionViaAttributes() from the Dao class with your additional filter and make direct use of the getmulti method.

Cheers

Thank you! As your suggestion:


            Dim group As GroupEntity
            Dim directories As DirectoryCollection
            Dim allDirectories As New DirectoryCollection
            Dim relations As New RelationCollection()
            Dim selectFilter As IPredicateExpression
            relations.Add(DirectoryEntity.Relations.AttributesEntityUsingDirectoryId, "Attributes_")
            relations.Add(AttributesEntity.Relations.GroupEntityUsingGroupId, "Attributes_", String.Empty, JoinHint.None)
            For Each group In currentUser.GroupCollectionViaUsers
                directories = New DirectoryCollection
                selectFilter = New PredicateExpression()
                selectFilter.Add(New FieldCompareValuePredicate(group.Fields(CInt(GroupFields.GroupId.FieldIndex)), ComparisonOperator.Equal))
                selectFilter.AddWithAnd(New FieldCompareNullPredicate(DirectoryFields.ParentId))
                directories.GetMulti(selectFilter, relations)
                allDirectories.AddRange(directories)
            Next
            Repeater1.DataSource = allDirectories
            Repeater1.DataBind()