You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have implemented a method that performs simple ordering on node set based on 2 integer properties MajorVersion/MinorVersion. I simply do a test on first node to see if nodes well have these properties and then do the ordering (see below).
I made some tests and noticed strange behaviours between theNodeSetobject and the expanded list for the same NodeSet when calling the .all() method.
Behaviour 1
Calling .first() method on NodeSet causes later calls to .all() to be filtered on the first node of the nodeset:
As you can see, calling .all() after the check on the first item in nodeset returns a list of 1 item while the nodeset contains 6 as expected.
Behaviour 2
As a workaround, I thought avoiding calling .first() method would do the trick but I noticed that once .all() is called, the order_by method no longer works on the nodeset:
As you can see in debug console, the languages are not sorted ascendingly by MajorVersion (version can be seen in field slug_languageid) as it should be.
I finally ended up with this workaround working well:
@staticmethoddeforder_by_version(nodes: List[NodeEntity]) ->List[NodeEntity]:
"""Order nodeset set by descending version. Nodes in the node set must have MajorVersion and MinorVersion attributes. """if (
nothasattr(nodes[0], "MajorVersion")
ornothasattr(nodes[0], "MinorVersion")
):
raiseAttributeError("Attributes 'MajorVersion'/'MinorVersion' not defined.")
nodes=sorted(nodes, key=lambdax: (-x.MajorVersion, -x.MinorVersion))
returnnodes
However I have the feeling that something is not working as expected regarding usage of nodeset / nodeset.all().
Thanks,
Gilles
The text was updated successfully, but these errors were encountered:
Sorry for the late answer. Thanks for looking at the issue.
Basically the scenario to reproduce the problem is quite basic:
For the first observation:
Populate a NodeSet nodeset object of length > 1 (no matter the type of nodes in it)
Call the method nodeset.first()
Call the method nodeset.all()=> you don't get a list of all nodes, but only a list containing the first node
For the second observation:
Populate a NodeSet nodeset object of length > 1 (no matter the type of nodes in it)
Call the method nodeset.all()
Then call the method nodeset.order_by("YOUR_PROPERTY").all() (you can order by any property you have defined on your nodes) => the list of nodes is not ordered as expected
Hi,
I am running neomodel 4.0.1.
I have implemented a method that performs simple ordering on node set based on 2 integer properties MajorVersion/MinorVersion. I simply do a test on first node to see if nodes well have these properties and then do the ordering (see below).
I made some tests and noticed strange behaviours between the
NodeSet
object and the expanded list for the same NodeSet when calling the.all()
method.Behaviour 1
Calling
.first()
method on NodeSet causes later calls to.all()
to be filtered on the first node of the nodeset:As you can see, calling
.all()
after the check on the first item in nodeset returns a list of 1 item while the nodeset contains 6 as expected.Behaviour 2
As a workaround, I thought avoiding calling
.first()
method would do the trick but I noticed that once.all()
is called, theorder_by
method no longer works on the nodeset:As you can see in debug console, the languages are not sorted ascendingly by MajorVersion (version can be seen in field slug_languageid) as it should be.
I finally ended up with this workaround working well:
However I have the feeling that something is not working as expected regarding usage of nodeset / nodeset.all().
Thanks,
Gilles
The text was updated successfully, but these errors were encountered: