# HG changeset patch
# User Augusto Mauch <augusto.mauch@openbravo.com>
# Date 1362049093 -3600
# Node ID fa16f64b5c9f7741e2dcaa940c29412a773d59e5
# Parent  a915e6a4b130585538aa7c688ad0b830e821ca62
Fixes issue 22523: It is possible to use a selector reference based on a view

The problem was that the referenced property of the column that used a selector reference based on a view was wrong. I.e. if a selector is created using the view m_product_price_warehouse_v, if the value field used is its product.id property, it would not be possible to save an order line using this selector because DAL would not be able to retrieve the product, it wo
uld try to fetch a record from the m_product_price_warehouse_v view using the product id, which is not the same as the view primary key.

To fix this, the user must set the column field of the defined selector so that it points to the entity used in the value field. A change has been done in SelectorDomainType.getForeignKeyColumn to ensure that this works with views.

diff --git a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/model/domaintype/SelectorDomainType.java b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/model/domaintype/SelectorDomainType.java
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/model/domaintype/SelectorDomainType.java
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/model/domaintype/SelectorDomainType.java
@@ -30,6 +30,7 @@
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Table;
 import org.openbravo.base.model.domaintype.BaseForeignKeyDomainType;
+import org.openbravo.base.model.domaintype.ForeignKeyDomainType;
 
 /**
  * Implements the domain type for a selector.
@@ -109,6 +110,11 @@
    * String)
    */
   public Column getForeignKeyColumn(String columnName) {
+    while (!column.isKey() && column.getDomainType() instanceof ForeignKeyDomainType) {
+      column = ((ForeignKeyDomainType) column.getDomainType()).getForeignKeyColumn(column
+          .getColumnName());
+      tableName = column.getTable().getName();
+    }
     return column;
   }
 
