fmdata icon indicating copy to clipboard operation
fmdata copied to clipboard

Get data's from a portal who have different TablePrefixFieldNames does not work

Open jakSolutionsGithub opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe.

I'm working with 3 tables -> Product, Order & OrderLine. For that, the relation is Product (pro__PRO::) > OrderLine (orl__ORL::) > Order (ord__ORD::). In Product layout, I have a portal (relation: pro_orl_ORD) who show every Order existing for this product. I need to get the quantity of product by order and this field is in Orderline table (pro_ORL). So my portal contain some fields of pro_orl_ORD and one field of pro_ORL.

Because of the below check, quantity field is not assigned since the full path is 'pro_ORL::qty' (and the TaBlePrefixFIeldNames of this portal is:"pro_orl_ORD"):

if (jp.Name.Contains(portalDataAttr.TablePrefixFieldNames + "::"))

Describe the solution you'd like

Add a new attribute (defaulted at false) to the class 'PortalDataAttribute' who will be something like 'DontIncludePrefix' and when it will be set at true, it will check without "::", allowing users to manually enter the fullname of the field (prefix+fieldName).

Describe alternatives you've considered

Get 2 models (one for each table prefix) but it's a waste of ressource since we receive the entiere portal from FileMaker.

jakSolutionsGithub avatar May 18 '22 11:05 jakSolutionsGithub

Let me make sure I understand what you currently have that doesn't work:

public class Product 
{
    [PortalData("ORDERS_PORTAL", TablePrefixFieldNames = "pro_orl_ORD")]
    public IEnumerable<ProductOrderDetails> Orders { get; set; }
}

public class ProductOrderDetails
{
    [DataMember(Name="orderId")]
    public int OrderId { get; set; }

    [DataMember(Name="qty")]
    public int Quantity { get; set; }
}

And what you would like to have instead is:

public class Product 
{
    [PortalData("ORDERS_PORTAL", TablePrefixFieldNames = "pro_orl_ORD", SkipPrefix = true)]
    public IEnumerable<ProductOrderDetails> Orders { get; set; }
}

public class ProductOrderDetails
{
    [DataMember(Name="pro_orl_ORD::orderId")]
    public int OrderId { get; set; }

    [DataMember(Name="pro_ORL::qty")]
    public int Quantity { get; set; }
}

Thus allowing you to control the source of each filed in the portal individually?

fuzzzerd avatar May 18 '22 21:05 fuzzzerd

Yup, exactly!

jakSolutionsGithub avatar May 18 '22 22:05 jakSolutionsGithub

That seems like a reasonable addition that won't break backwards compatibility. If you want to submit a PR I'd be happy to review and work with you to get it merged. Otherwise, I will keep it on the backlog as a future enhancement.

fuzzzerd avatar May 20 '22 16:05 fuzzzerd

PR's done, let me know if you need any change or anything!

jakSolutionsGithub avatar May 21 '22 10:05 jakSolutionsGithub