I am using kentico application where i have to delete all child items which contains either node id of parent or parentnodeid of parent based on the child inside there.
Below is the screen shot:
In this picture we can see we have a parent node called membership and inside one child called Blog. Under of Blog which node id is 583 having 29 child. Now I am running a code and getting all the child data under of that parent as a list.
Below is the screen shot:
Now i have to remove all the child data from list whose parentnodeid or parent-parent node id is 583 (Blog).
Below is the code used to get the list of all parent and child items:
TreeProvider tree = new TreeProvider();
var childNodeDataSet = tree.SelectNodes(childNodeId, null, SiteContext.CurrentSiteName);
var getAllChildItems = childNodeDataSet.Items[0].AllChildren;
var getItems = getAllChildItems.ToList().OrderBy(a=>a.NodeAliasPath);
As we can see above code childNodeId is nothing but the Membership page node id. Using this i am getting all the child items.
Now in this getItems i have all the values where i have to remove Blog page parent and child completely.
I tried this code to remove the matching parent item from list:
string excludeFileName = "583, 683, 686, 687";
string[] arrStringList = excludeFileName.Split(',');
foreach (var excName in arrStringList)
{
getItems.RemoveAll(a => (a.NodeID == Convert.ToInt32(excName.Trim()) || a.NodeParentID == Convert.ToInt32(excName.Trim()))
|| (a.Parent.NodeID == Convert.ToInt32(excName.Trim()) || a.Parent.NodeParentID == Convert.ToInt32(excName.Trim()))
|| (a.Parent.Parent.NodeID == Convert.ToInt32(excName.Trim()) || a.Parent.Parent.NodeParentID == Convert.ToInt32(excName.Trim()))
|| (a.Parent.Parent.Parent.NodeID == Convert.ToInt32(excName.Trim()) || a.Parent.Parent.Parent.NodeParentID == Convert.ToInt32(excName.Trim())));
}
This code is working fine if i know particular node has how many level.
But if some of the node don't have that much level then in that case this code is giving exception.
If found any issues please let me know.
I am a little confused at the path you're taking. If you want to get all children of a particular node, why not just get all nodes where the NodeAliasPath is like "The/Parent/Node/Path"+"/%"?
This will select all the children nodes all the way down.
If you only want to grab a certain number of levels, you can get the Parent's NodeLevel, and then in the query add a NodeLevel <= "+(ParentNodeLevel+2) to grab all the children and grandchildren only.
To exclude certain nodes, you can also put a "NodeID not in (123,234)".
Perhaps if you can clearly say what you are trying to accomplish we can help out easier!
PS: I Put the SQL, but the DocumentQuery object has most of these in methods, like .WhereNotIn("NodeID", ListOfNodeIDsToExclude)
Related
I'm currently optimizing doctrines queries, and noticed that doctrine generate extra queries on data it already got in the unit of work (UOW).
Yet, when I try to add/associate child objects to it's parent, Doctrine is querying to get all the childs (which are already in the UOW)
This is how I do it :
//Getting (root) Salle of the view
$salle=$salleRepository->findBy(array('isAccueil'=>true));
//Get '$salle' children
$salles=$salleRepository->findBy(array('salle'=>$salle));
//For each children of each `Salle` in $salle
foreach($salleRepository->findBy(array('salle'=>$salles)) as $child) {
//Go through each parent
foreach($salles as $parent) {
//If parent id match child parent id
if($parent->getId() == $child->getSalle()->getId()) {
//Doctrine extra query happen here
//Query for current parent's children
$parent->addSalle($child);
}
}
}
As written in code comment, Doctrine query for current parent's children.
But those children already exists in the UOW, I did query for them on the first foreach.
Is there a way to reassociate children to parent so Doctrine won't do extra query?
You're executing those two queries right at the beginning.
Doctrine's unit of work (UOW) is not a result-cache. You probably misunderstood that.
// FIRST
$salles=$salleRepository->findBy(array('salle'=>$salle));
// SECOND
foreach($salleRepository->findBy(array('salle'=>$salles)) as $child) {
You should instead combine those two queries into a single query inside your repository.
Example:
// tip: don't use assignments in loop definitions and conditional statements
$children = $salleRepository->findSalleBySallesSalle($salle);
$foreach ($children as $child) {
// ..
}
Think about it like this:
What if the database changed between those 2 queries and you really wanted two different results?
Doctrine does let you configure a separate query- and result-cache but here you should just use a combined query.
I want to return a $firebaseArray of records that contain a particular value without knowing the parent ID.
So in this case, I want to get all the objects under 'challenges' that contain the ID pictured above starting with LNF.
I have tried using orderByChild and equalTo, but again this seems to requiring knowing the parent ID. Is there a way around this?
If you want everything with key CPjip3tVE1Q067Qzx6p0vij0k1|1try this:
var key = "CPjip3tVE1Q067Qzx6p0vij0k1|1";
for child in snapshot.children {
if child.key == key {
get your data
}
}
You can use that to loop over all of the children under "challenges"
thanks for reading and helping. Here is my situation so far:
I have much data in database, each piece of data has id, parentid(which means you can find the id of its parent using this parentid ), name, description.
I want to create a dynamic tree using react,but I do not know how many levels of nodes I have. Each node represents for an id in database. An user clicks on a node A on this tree, the children nodes whose parentid equals to A's id will show/hide.
I do not intend to retrieve all the data because it will take long time. Now I am able to get one node's children by sending request and get response.body:
getChildren(id){
ajax.get('http://localhost:8080/configmgmt/code/category/retriveTree/' + id)
.end((error, response) => {
if (!error && response) {
console.dir(response.body );
this.setState(subdata:response.body});
} else {
console.log('There was an error fetching from database', error);
}
}
);
}
in render part, I wrote:
{this.state.subdata.map((rb,index)=>{
return <li><div>{rb.name}</label></div></li>})
}
Here comes the question, I still do not know how to create the tree recursively(because any node might has its children nodes ). how to do this when we can only get a node's children nodes from the database?
I would do your task in two steps:
Create a structure for an augmented tree with loading status flags. It should have a structure like this (this is pseudocode):
class Node {
loaded: boolean,
expanded: boolean,
children: list<Node>
}
Create a component for this:
If node isn't expanded don't render its children
If use clicks on expand sign
If children are loaded, do nothing, just change the expanded field
If children aren't loaded
set expanded to true
initiate ajax request
as soon as the request completes, set loaded to true, and assign children
Creating a component which recursively uses itself isn't a problem. If you don't know how to do this read here: how to render child components in react.js recursively
I am using backbone.js. The elements in my collection are just in the order that they are added. However, I want the ability to switch the position of elements. How do you do this?
You could do something like this:
var MyCollection = Backbone.Collection.extend({
swapItems : function(index1, index2) {
this.models[index1] = this.models.splice(index2, 1, this.models[index1])[0];
}
});
This accesses the models array directly then will swap the items specified by the indices.
class Person{
#Persistent
private List tags = ArrayList()
}
I want to let the user query a person based on his/her tag, so I had my query filter like this:
tags.contains(tagValue1)
and if the user want to search for multiple tags, I would just add to the filter so if the user is searching for 3 tags, then the query would be
tags.contains(tagValue1) && tags.contains(tagValue2) && tags.contains(tagValue3)
I think this approach is wrong, because the datastore then needs to have an index that have the tags property three times... and if the user search for more than 3 tags at a time then it will be broken.
What's the proper way to do this? Do you guys have any suggestions?
Can't answer on the specifics of how GAE/J's plugin processes that but a marginally better query would be
tags.contains(theTag) && (theTag == tagValue1 || theTag == tagValue2 || theTag == tagValue3)
so "theTag" is a variable.