How to use field.setForeignKey()...

Hi,

I’ve searched but i couldn’t find any example.

I have 2 RPC data sources,
1st vendor: with 2 fields"

DataSourceIntegerField idField = new DataSourceIntegerField("vendor_id");
		idField.setPrimaryKey(true);
		idField.setHidden(true);
		
		DataSourceTextField name = new DataSourceTextField("vendor_name", "Name");
		name.setRequired(true);
		name.setCanEdit(true);

2nd ds - document for this vendor:

DataSourceIntegerField idField = new DataSourceIntegerField("document_id");
		idField.setPrimaryKey(true);
		idField.setHidden(true);
DataSourceIntEnumField vendorField = new DataSourceIntEnumField("document_vendor_id", "Vendor");
		vendorField.setRequired(true);
		vendorField.setCanEdit(true);
vendorField.setTypeAsDataSource(new VendorRPCDataSource());
		vendorField.setForeignKey("vendor_name");

but on the list grid created from this (document) data source I’m getting int values instead of vendor names. What am I doing wrong?
Thanks for any help.

I believe the foreign key of document needs to reference the idField of vendor.
Try that.

Don’t setTypeAsDataSource. Set the type as the actual type of the foreignKey (eg, integer).

This just declares the relationship. See ListGridField.optionDataSource and SelectItem.optionDataSource to understand how to enable fetches for related data.