Ticket #1151 (closed defect: fixed)

Opened 3 months ago

Last modified 3 months ago

child-parent relation after parent.new with ParentLinkField

Reported by: kweinert Assigned to: somebody
Priority: major Milestone: 0.8.3
Component: biz Version: 0.8.2
Keywords: Cc:

Description

Hello,

still studying the Parent-Child bizobj structure, I have a small suggestion:

in dBizobj._setParentLinkField, wouldn't it be nice to insert a check if the named parent link field is in Parent.NonUpdateFields?? -- And if is not, log a warning or something? As this is an one-time-operation, it is not expensive.

Or otherwise, could dBizobj.setFieldVal be adapted to notify its children so they can "move" to the right dataset? (BTW: currently, setFieldVal references an undefined variable ret if self._CurrentCursor is None.)

In my small example, I did on the parent

parent.setFieldVal("non_pk_key", "myvalue") # child.ParentLinkField? = "non_pk_key" parent.requeryAllChildren()

which works nice (i.e. the child shows the right dataset). If I call parent.new() before that, however, the child's dataset remains empty.

Below there is a testcase showing the problem.

Attachments

testParentChildWithRefToNonPK.py (4.6 kB) - added by kweinert on 04/30/08 08:16:29.
unittest testcase

Change History

04/30/08 08:16:29 changed by kweinert

  • attachment testParentChildWithRefToNonPK.py added.

unittest testcase

04/30/08 13:08:26 changed by ed

This sounds like it is an app-specific problem, and not a framework-level problem.

If you have a situation where you need to requery a child based on a parent field's value changing, you might want to just add code to the parent bizobj's validateField() method instead. This way it will get called automatically when the parent field's value changes.

Unless others can verify that this is a common approach used in applications, I think it's best implemented as code in your app, and not in the framework.

05/03/08 05:47:45 changed by kweinert

  • status changed from new to closed.
  • resolution set to fixed.

05/04/08 13:50:16 changed by ed

Wanted to annotate this issue with the fact that there were several places in the code where the parent-child relationship was assumed to be based on the parent's PK. This issue brought those bugs to light, and they have all been fixed.