Skip to main content
Solved

Foreign Key Not Displaying in DAC Despite Correct Configuration

  • Jun 19, 2024 6:44 PM UTC
  • 3 replies
  • 165 views
  • Translate All

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

3 replies

Forum|alt.badge.img+11
  • Captain II
  • Jun 26, 2024 10:27 AM UTC

Hi @kdesbiens 

 

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

 

Translate

Forum|alt.badge.img+11
  • Captain II
  • Answer
  • Jun 26, 2024 10:35 AM UTC

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)

Translate

snikomarov36
Acumatica Employee
Forum|alt.badge.img
  • Acumatica Employee
  • Jun 26, 2024 11:00 AM UTC

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

Translate