Re: Looking for a WORelaretoOne that filters some records

Lachlan Deck <[email protected]>
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Hi there,

On 24/03/2006, at 5:00 AM, jesus Guzman wrote:

> I am trying to get a popup or browse list for picking a relate to  
> one record, but i need to list only
> records that have a certain status.

No worries...

> i tried to use an inherited class for that has the selector (st=1),  
> but then my project became harder to code because I have 2  
> relations one to the regular object
> and the other to the sublcass that has a selector.

Indeed.

> sometimes therelated one record changes again of status. bot the  
> initial status has to be one at first assignment.
>
> I would like to have a WOToOneRelationship with a fetchSpec so that  
> the list is shorter, and I do not have to validate status when  
> saving the record

1) see the api for the bindings of WOToOneRelationship:
<file:///Developer/ADC%20Reference%20Library/documentation/WebObjects/ 
Reference/WOJExtensions/WOToOneRelationship/chapter_33_section_3.html>

2) The one you're interested in is 'dataSource' (the data source for  
the destination objects). It takes an object of type  
'EODatabaseDataSource'.

3) Now we look at the api for 'EODatabaseDataSource'. And you can  
deduce that you'll need a dataSource binding..

public EODatabaseDataSource toOneDataSource() {
	EOEntity anEntity;
	EORelationship aRelationship;
	EODatabaseDataSource aDestinationSource;
	EOQualifier destinationQualifier;
	
	//
	// construct EODatabaseDataSource object from
	// - source object, and
	// - toOne relationship key
	//
	anEntity = EOModelGroup.defaultGroup().entityForObject( sourceObject 
() );
	aRelationship = sourceEntity.relationshipNamed( toOneRelationshipKey 
() );
	anEntity = aRelationship.destinationEntity();
	aDestinationSource = new EODatabaseDataSource 
( sourceObject.editingContext(), anEntity.name() );

	//
	// add fetch spec to EODatabaseDataSource to limit objects found (if  
applicable)
	//
	destinationQualifier = ...; // qualifier for destination objects
	aDestinationSource.setFetchSpecification( new EOFetchSpecification 
( anEntity.name(), destinationQualifier, null ) );
	
	return aDestinationSource;
}

with regards,
--

Lachlan Deck
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.