Add Filter to Single-Entity Fetch?

Posts   
 
    
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 26-Oct-2005 17:39:45   

Frans,

Odd question, but you're used to that from me. simple_smile

Is there a way to add a filter to a single entity fetch (using a PK)?

I need this because we have a (very) complex security system, where some entity access relies on joins.

I can't give a "real" illustration without giving details about a client's schema. But imagine a user trying to fetch an order for a customer, and the user's access to that customer was determined by a third table, call it customer_user_access. So we would have to create relations Order=>Customer=>Customer_User_Access and use the user_id as a filter.

What I may need to do is fetch a typed list first (with filtering/relations), and then only fetch the entity if the typed list returns a row. If I could do it with a filter/relations on the entity fetch, that would be preferable.

I hope that all makes sense. It's actually more complex than my illustration, but the main question is simple. simple_smile

Thanks,

Phil

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Oct-2005 19:16:06   

What I'd do in such a situation, is do an entity collection fetch and pass the relation/filters you want and grab the first element. The PK is already unique, so if you already know hte PK, you can fetch it directly.

Frans Bouma | Lead developer LLBLGen Pro
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 26-Oct-2005 20:24:58   

Otis wrote:

What I'd do in such a situation, is do an entity collection fetch and pass the relation/filters you want and grab the first element. The PK is already unique, so if you already know hte PK, you can fetch it directly.

Hmm. I'm not sure I follow.

I think what confuses me is where you say "fetch it directly." I do know the PK, I just can't tell if the user has access to the record without the relations.

Do you mean add the PK to the filter?

  1. Create a relation and filter for the security access tables
  2. Add the PK to the filter
  3. Fetch the collection using the filter and relations (should only return one or zero entities)
  4. Use the first entity if one is returned.

I think that will work, whether that's what you meant or not. wink But let me know if you think there is a better way (or if you meant something different).

Thanks again!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Oct-2005 20:39:34   

That's what I meant indeed. I didn't think of security tables and access credentials, in which case having the PK is not that useful wink .

You can specify '1' for the amount of elements to return with the fetch.

Frans Bouma | Lead developer LLBLGen Pro