限制用户为播放器添加5个以上的属性

时间:2022-10-03 11:33:46

I have tableA (fields: playerId, skill)

我有tableA(字段:playerId,技能)

So my question is: how to make so that user can not add more than 5 same playerId?

所以我的问题是:如何使用户无法添加超过5个相同的playerId?

Table's which method to override and what to do?

表的覆盖方法和做什么?

Tanks...

坦克...

1 个解决方案

#1


2  

You can create a new integer field AttributeNum. You can override the insert() or the initValue() on the table depending on you requirement. Choose initValue() over insert() if you would like to keep your set-based operation fast on this table.

您可以创建一个新的整数字段AttributeNum。您可以根据您的要求覆盖表上的insert()或initValue()。如果要在此表上快速保持基于集合的操作,请在insert()上选择initValue()。

In the overriden method you can use query to aggregate and count the number of attributes per your current record.

在overriden方法中,您可以使用查询来聚合和计算当前记录的每个属性数。

Edit:

编辑:

Alternately you can just override the validateWrite() method on the table.

或者,您可以覆盖表上的validateWrite()方法。

boolean validateWrite()
{
    TableA        tableA;
    boolean       ret = super();    
    #define.MaxAttributes(5) // consider using setup         
    if (ret && !this.RecId)
    {
        select count(RecId) from tableA where tableA.PlayerId == this.PlayerId;    
        if (tableA.RecId >= #MaxAttributes)
        {    
            ret = checkFailed("Error message goes here");
        }    
    }
    return ret;
}

You didn't specify if the attributes should be unique per player or not but you should also consider creating the appropriate index in order to enforce data integrity.

您没有指定每个播放器的属性是否应该是唯一的,但您还应考虑创建适当的索引以强制实施数据完整性。

You can find more information here:

您可以在这里找到更多信息:

Maintain Fast SQL Operations [AX 2012]

维护快速SQL操作[AX 2012]

Speeding Up SQL Operations [AX 2012]

加快SQL运营[AX 2012]

Maintaining Data Integrity [AX 2012]

维护数据完整性[AX 2012]

Data Model for New Microsoft Dynamics AX Modules [AX 2012]

新Microsoft Dynamics AX模块的数据模型[AX 2012]

Where to Place the Code [AX 2012]

在何处放置守则[AX 2012]

#1


2  

You can create a new integer field AttributeNum. You can override the insert() or the initValue() on the table depending on you requirement. Choose initValue() over insert() if you would like to keep your set-based operation fast on this table.

您可以创建一个新的整数字段AttributeNum。您可以根据您的要求覆盖表上的insert()或initValue()。如果要在此表上快速保持基于集合的操作,请在insert()上选择initValue()。

In the overriden method you can use query to aggregate and count the number of attributes per your current record.

在overriden方法中,您可以使用查询来聚合和计算当前记录的每个属性数。

Edit:

编辑:

Alternately you can just override the validateWrite() method on the table.

或者,您可以覆盖表上的validateWrite()方法。

boolean validateWrite()
{
    TableA        tableA;
    boolean       ret = super();    
    #define.MaxAttributes(5) // consider using setup         
    if (ret && !this.RecId)
    {
        select count(RecId) from tableA where tableA.PlayerId == this.PlayerId;    
        if (tableA.RecId >= #MaxAttributes)
        {    
            ret = checkFailed("Error message goes here");
        }    
    }
    return ret;
}

You didn't specify if the attributes should be unique per player or not but you should also consider creating the appropriate index in order to enforce data integrity.

您没有指定每个播放器的属性是否应该是唯一的,但您还应考虑创建适当的索引以强制实施数据完整性。

You can find more information here:

您可以在这里找到更多信息:

Maintain Fast SQL Operations [AX 2012]

维护快速SQL操作[AX 2012]

Speeding Up SQL Operations [AX 2012]

加快SQL运营[AX 2012]

Maintaining Data Integrity [AX 2012]

维护数据完整性[AX 2012]

Data Model for New Microsoft Dynamics AX Modules [AX 2012]

新Microsoft Dynamics AX模块的数据模型[AX 2012]

Where to Place the Code [AX 2012]

在何处放置守则[AX 2012]