Does a prefetchPath alway return a collection?

Posts   
 
    
Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 11-Sep-2007 14:42:40   

Hi, I think it is like this, but just to make sure. If you use prefetchPath is always returns a collection. Right.

But only if there are records to fetch, of course.

So in the BL there has to be logic to retrieve just a single record, even if you can be sure the collections will only have one or null values. I mean when a employee can only be part of one department using prefetchpath to retrieve the department the employee belongs to, it will return only one record. Right? But this is still a collection, so I have to use something like collection[0] to get this record.

Just to make sure. Right?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Sep-2007 18:28:18   

A prefetch path is a graph representation what to fetch. the fetch results end up in the entities and the entity collections. So if you fetch employee m:1 department, using a prefetch path, you'll get 1 department entity. However if the relation is employee 1:n department, although there's just 1 department entity for every employee, then of course, the department entity is placed inside 'Departments' so you have to grab the first entity in the set.

Frans Bouma | Lead developer LLBLGen Pro
Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 11-Sep-2007 19:08:00   

Thanks Otis, I thought so. Just wanted some confirmation.