Macro for adding entities and sequences to PostgreSQL model ends with failed tests

Hi!

TDM Version 5.4, PostgreSQL 9.2 model.

I’m developing a macro that adds an Entity and its related sequence to PostgreSQL model. After macro ends I launch a model test and I get this message:

Nonpaired objects “TPERCustomObject.<name_of_seq>” and"TPEREntity.<name_of_entity>", property “OwnedByTable”. Back link is missing.

Macro for adding tables:

Entity = Model.CreateNewObject(2002); // add new entity
Entity.Name = “…”;
Entity.Caption = “…”;
//…code for adding attributes, PK, …, and other table stuff

Macro for adding sequences:

var seq = Model.CreateNewObject(51000); //sequence
seq.Name = “…”;
if (seq.SupportsProperty(“OwnedByTable”)) {
seq.OwnedByTable = Entity;
seq.OwnedByColumn = prefix + “_CODE”;
var atr = Entity.Attributes.GetObjectByName(seq.OwnedByColumn);
atr.DefaultValue = “nextval(’” + nomSeq + “’)”;
}
if (seq.SupportsProperty(“StartWith”)) {
seq.StartWith = “1”;
}
if (seq.SupportsProperty(“IncrementBy”)) {
seq.IncrementBy = “1”;
}
if (seq.SupportsProperty(“Cache”)) {
seq.Cache = “10”;
}
if (seq.SupportsProperty(“Comments”)) {
seq.Comments = "Secuencia para " + Entity.Name + “.” + prefix + “_CODIGO”;
}

What does it means “Back link is missing.”? Some kind of “link” in the table or attribute?

Am I missing some step in my code?

Thanks in advance.

Regards!

Hi,

this message means that you create link from Sequence to Entity, but not link from Entity to Sequence.

After line

seq.OwnedByTable = Entity;

insert

Entity.Sequences.Add(seq);

Daril

Hi Daril,

Thanks for your answer!

I actually tried your piece of code before posting (I forgot to mention it, sorry). But I got an error:

“Microsoft JScript runtime error Object doesn’t support this property or method”

Documentation say that this property is a PGSequence:

Name Datatype Attributes Defined in Description Src
Sequences Read only Overrideable PERSequencePG91 DatabasePostgreSQL91.txm

Then I try this:

Entity.Sequences = seq;

With no errors during runtime. But when I perform a model test:

64 | 07/06/2017 15:04:25 | Test Start | Test Start | 0 | 1 | 7364| 0
65 | 07/06/2017 15:04:25 | Failed test TCSBaseTest.TestExistenceOfObjectsInNoOwnedLists | Interface not supported | 0 | 4 | 7364| 0
66 | 07/06/2017 15:04:25 | Failed test TCSBaseTest.TestPairingObjects | Interface not supported | 0 | 4 | 7364| 0
67 | 07/06/2017 15:04:25 | Failed test TCSBaseTest.TestRepletenessPropertyICSList | Interface not supported | 0 | 4 | 7364| 0
68 | 07/06/2017 15:04:25 | Failed test TCSBaseTest.TestDuplicityOfObjectInList | Interface not supported | 0 | 4 | 7364| 0
69 | 07/06/2017 15:04:25 | Failed test TCSBaseTest.TestHashLists | Interface not supported | 0 | 4 | 7364| 0
70 | 07/06/2017 15:04:25 | Test End | Test End | 0 | 1 | 7364| 0

And the model turns totally KO.

Regards,

Hi,

sorry in TDM version 5.4. List doesn’t support method Add. My Fault.

Try to use

Entity.LinkObject(seq);

instead

Entity.Sequences.Add(seq);

Entity.Sequences is already List in Reference Guide is bug. You can try write Log.Information(Entity.Sequences.Classname) to log to check it.

Daril

Hi!

sorry in TDM version 5.4. List doesn’t support method Add. My Fault.

Don’t worry about that!!

Try to use

Entity.LinkObject(seq);

That’s it! I changed the code and it’s all OK now. No runtime errors and no failed tests.

Thanks for your time!

Regards,

Hi,

sorry in TDM version 5.4. List doesn’t support method Add. My Fault.

Don’t worry about that!

**

Try to use

Entity.LinkObject(seq);

That’s it! I changed my code and all is OK now. No runtime errors, no failed tests.

Thanks again!

Regards,

PS: I try to mark your answer, but post remains marked as unanswered.