Why do I need to add relationships for child and parent?
Child child = Session.Get(1);
Parent parent = Session.Load(1);
parent.Children.Add(child);
child.Parent = parent;
It works perfectly without parent.Children.Add(child) if use inverse=true and I don't need Children collection in current session (session per web request). Do you always add relationship for child and parent?
Setting child.Parent = parent is enough to persist the relationship.
However, if you don't add the child to the collection, you won't be able to take advantage of cascading, so you'll have to persist the child explicitly.
Also, if you don't set one of the sides, you'll have an inconsistent memory model (because the child won't be added to the collection unless you reload it).
I hope I understood you correctly.
class Parent { List Children {get;set;}
class Child { Parent Parent {get;set;}
ANS1. In this scenario Inverse tells the nhibernate framework to leave the control mechanism of [Parent-Child] relationship to the Child (it is mostly about which object is responsible for Deleting/Updating the Child). With Inverse attribute on Children property Child is responsible for itself, otherwise Parent is responsible for deleting a Child.
ANS2. You do not need both properties (Children, Parent) in most cases (you need them if you specify inverse=true on Children). It only depends on the functionality you want to get.
Does this briefly answer your question?
Related
I am confused about components data.
Parent to Child use props.
Child to Parent use emit.
I am thinking about difference.
What I have learned, emit need event to transfer data.
So, the example, I learned it always combine event like 'click'
This is point what I confused.
Why child to parent need emit event to send data.
I am think about are there certain way send data from child to parent no use event?
Coming from iOS, I am stuck at NSOutlineView as Source list, I have read many resources but cannot grasp it clearly.
What I want is, just to show coreData ToMany relationship as sourceList using NSTreeController. I am persisting data from text file to disk.
Entities and relations are as follow:
Group >> Item >> Description
SourceList Example:
My app do not allow user to create any new Entity, just to view what saved from TextFile. I can do this by NSArrayController but I need to show data in single table with hierarchy.
In NSArrayController, I only needed to bind managed object context to Parameter and and object controller to Entity Name. On TableView I needed to bind content and selection indexes to NSArrayController.
How can I bind NSTreeController to SourceList and when children is selected, show another ToMany relation from Item to Description.
I can think of two solutions and maybe there is a better one.
Solution 1:
Create a subclass of NSTreeController and override
- (NSString *)childrenKeyPathForNode:(NSTreeNode *)node
the managed object is node.representedObject.
Solution 2:
Create NSManagedObject subclasses and implement a children method which returns the child relationship.
- (NSSet *)children {
return self.itemsInGroup;
}
Set childrenKeyPath of the tree controller to 'children'.
I think solution 2 feels wrong, managed objects shouldn't contain code for views, but it is very easy to implement if you already have NSManagedObject subclasses.
Is it possible to receive notifications if, for a specific parent AXUIelement, any of it's children change (an attributes), or a child is added/removed?
For added/removed You can get notified if an element is created with NSAccessibilityCreatedNotification (and then check if it has the appropriate parent) and destroyed with NSAccessibilityUIElementDestroyedNotification. I don't see a accessibility notification for arbitrary attribute changes.
If I changed my NSOutlineView from using bindings and an NSTreeController to having a data source and a delegate, how would I automatically update the NSOutlineView, if my model tree changes? Should I observe the childNodes property of every single node in my tree with my controller and trigger a reload when a change occurs? Or is there another way?
That's one way. Another way would be for the model to post notifications when it changes and have your controller observe those.
Also, a model doesn't typically change spontaneously. Usually, the change is initiated outside of the model in response to some event. A controller is usually doing that. So, that controller could also provoke an update to the outline view. (There may be multiple controllers, so maybe the controller that initiates the model change just informs a window or view controller, which would be responsible for updating the outline view.)
I asked a similar question that was marked as duplicate here: Recommended Pattern for Observing Changes in Tree Structure [duplicate]
I wanted to avoid using NSTreeController as it means you lose control of animations when updates occur.
I have an MVVM set up. My model is a graph, my view model is a tree. There is a one-one relationship between any tree nodes and a graph node. As detailed in the question above, there is obviously a many-one relationship between the tree nodes and an outline view.
So, I settled with...
The view-model tree nodes need to know when their children are updated, so I used KVO of the associated graph node to catch when children are added or removed.
For the outline view update I settled on a model-view delegate that I implement on the view-controller. Each tree-node in the view model can call delegate methods on the tree root when children are added or removed. This felt the clearest approach to me, and easily debuggable. I didn't want chains of things happening behind the scenes.
The final outline view update call felt satisfyingly simple:
func itemsInserted(atIndexes indexes: IndexSet, forParent parent: ECViewModelNode) {
outlineView?.insertItems(at: indexes, inParent: parent, withAnimation: .slideDown)
}
At the table-cell-view level I bind directly to the details of the graph model nodes.
I am trying to figure out the purpose of what the .parent property achieves in this method and the "get[ClassNameHere]" methods in general that feature this property being called.
-(HudLayer*) getHud
{
return (HudLayer*)[self.parent.parent.parent getChildByTag:kTagHudLayer];
}
It's not possible to know the details from just this method shown here. But the .parent does return the Cocos parent, sprite or layer, to which the current cocos object belongs as a child. Essentially this code suggests you have a sprite or layer with a child that has more children and more children of those children, and this is a way to find out who the big parent up the stream is, and then get a new child from that parent.
Personally it seems pretty sloppy to me. I'd never code that way myself. Hard to read (as you can see) and having so many parent properties strung together like this is opening a lot of room for bugs. It would be wiser if the top parent did what it needs to do rather than a distant grandchild going up the chain; it breaks the MVC model a bit to do it as shown here.
Probably class HudLayer has a parent property that points to another object of the same kind, thus having a parent property pointing to another HudLayer and so on, climbing up for three levels. Then it just sends a getChildByTag message to it.