Skip to main content
Solved

Foreign Key Not Displaying in DAC Despite Correct Configuration


Hello,

I am encountering an issue with the display of a foreign key in my Data Access Class (DAC) within Acumatica. Despite following the documentation and ensuring that the relationships and configurations are correctly set, the foreign key does not appear in the DAC UI.

Brewery DAC :

using System;
using PX.Data;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data.BQL.Fluent;

namespace Assainissement
{
    [PXCacheName("Brewery")]
    public class Brewery : IBqlTable
    {
        [PXDBIdentity(IsKey = true)]
        public virtual int? BreweryID { get; set; }
        public abstract class breweryID : PX.Data.BQL.BqlInt.Field<breweryID> { }

        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Name")]
        public virtual string Name { get; set; }
        public abstract class name : PX.Data.BQL.BqlString.Field<name> { }

        [PXDBBool]
        [PXDefault(true)]
        [PXUIField(DisplayName = "State")]
        public virtual bool? State { get; set; }
        public abstract class state : PX.Data.BQL.BqlBool.Field<state> { }
    }
}

Beer DAC : 

using System;
using PX.Data;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data.BQL.Fluent;

namespace Assainissement
{
    [PXCacheName("Beer")]
    public class Beer : IBqlTable
    {
        [PXDBIdentity(IsKey = true)]
        public virtual int? BeerID { get; set; }
        public abstract class beerID : PX.Data.BQL.BqlInt.Field<beerID> { }

        [PXDBString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Name")]
        public virtual string Name { get; set; }
        public abstract class name : PX.Data.BQL.BqlString.Field<name> { }

        [PXDBBool]
        [PXDefault(true)]
        [PXUIField(DisplayName = "Active")]
        public virtual bool? Active { get; set; }
        public abstract class active : PX.Data.BQL.BqlBool.Field<active> { }

        [PXDBInt]
        [PXDefault(typeof(Brewery.breweryID))]
        [PXUIField(DisplayName = "BreweryID")]
        [PXSelector(typeof(Search<Brewery.breweryID>),
                    typeof(Brewery.name),
                    SubstituteKey = typeof(Brewery.name),
                    DescriptionField = typeof(Brewery.name))]
        [PXForeignReference(typeof(Field<Beer.breweryID>.IsRelatedTo<Brewery.breweryID>))]
        [PXParent(
            typeof(Select<Brewery,
                    Where<Brewery.breweryID,
                    Equal<Current<Beer.breweryID>>>>)
        )]
        public virtual int? BreweryID { get; set; }
        public abstract class breweryID : PX.Data.BQL.BqlInt.Field<breweryID> { }
    }
}

 

Result :

 

Best answer by aiwan

After this you will be able to use the below in your field declaration.

[PXDBDefault(typeof(YourParentDac.ParentKeyField))]
[PXParent(typeof(FK.YourForeignKey))]

 

This link from the wiki should help too.

To Define a Foreign Key (acumatica.com)

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+8
  • Captain II
  • 366 replies
  • June 26, 2024

Hi @kdesbiens 

 

Have you tried to declare the keys like in the below screenshot?

 


Forum|alt.badge.img+8
  • Captain II
  • 366 replies
  • Answer
  • June 26, 2024

After this you will be able to use the below in your field declaration.

[PXDBDefault(typeof(YourParentDac.ParentKeyField))]
[PXParent(typeof(FK.YourForeignKey))]

 

This link from the wiki should help too.

To Define a Foreign Key (acumatica.com)


snikomarov36
Acumatica Employee
Forum|alt.badge.img
  • Acumatica Employee
  • 54 replies
  • June 26, 2024

Hi @kdesbiens,

In addition to @aiwan’s answer, you can also use Acuminator to generate FK keys in your DAC more easily in Visual Studio. Acuminator has PX1034 diagnostic that can help you with the Foreign Key generation. See the details in the diagnostic documentation:
https://github.com/Acumatica/Acuminator/blob/dev/docs/diagnostics/PX1034.md


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings