I adds linked document to another like this (ok):
create class Doc
create class ParentDoc
create property ParentDoc.children LINKLIST
insert into Doc set name = 'doc1' #12:0
insert into Doc set name = 'doc2' #12:1
insert into ParentDoc set name = 'pd', children = [#12:0] #13:0
update #13:0 add children = #12:1
Now I want select all children from #13:0:
select children from #13:0
returns me only ids of children
traverse children from #13:0
returns me parent and children
What is correct way to fetch full children records only?
You can use
select expand(children) from #13:0
Related
From the documentation I can figure out how to replace or add a value at from an existing property
{"example":123}
UPDATE mytable
SET jsoncolumn = jsonb_set(jsoncolumn, '{example}', '"string123"')
WHERE id = 1;
{"example":"string123"}
However, I cannot figure out how to insert a property at the top level (beside a sibling)
{"example":123}
{"example":123,"property-to-add":"value"}
What is the easiest way to accomplish this (given that the actual object is pretty large)
You can append the new key/value pair:
UPDATE mytable
SET jsoncolumn = jsoncolumn || '{"property-to-add": "value"}'
WHERE id = 1;
If property-to-add already exists, it will be replaced.
I want to get the detail entity of a parent entity with a custom method in this method I want to sort the detail entity random and exclude the details by a condition it's possible in the parent method set the method for get the childs of the parent entity?
In your example I have order and orderdetail like this:
OrderId = 1
date = 2015-06-01
Order detail
Order id = 1
Product = 1
RowNumber = 2
Order detail
Order id = 1
Product = 2
RowNumber = 3
I need that the order details shoul be order by rownumber in a random sort and I want that I get in the order object when I acces to the detail like Order.OrderDetails I get the orderdetails in random I have a method that returns the orderdetail in random but I don't set how set in the graphical design to set my method for get the orderdetails list collection. Other dude I try to add a cfl method for order random something like this in the order detail object
LOAD (int orderId) WHERE orderId = #orderId ORDER BY NEWID()
SELECT * FROM table ORDER BY NEWID()
and get a random order but I get and error so I add a partial class to order by random and add for example an product id like this a)2 b) 1
You can create a CFQL method with inline SQL:
<cf:method name="LoadByOrderRandom"
body="LOAD(Order) where Order = #Order order by [newid()]"
checkLevel="None" />
More information about raw methods: http://blog.codefluententities.com/2014/07/03/cfql-raw-methods/
I have three tables: Superobject, object_master and object_child.
SuperObject contains superobj_id and obj_id. obj_master contains all the details about the object.
Object_child has two columns: obj_id and child_id. It contains object and its child. A child can also have a subchild. So, an object can have multiple childs.
SuperObject Table object_child table
sobj1 obj1 obj1 ch_obj1
sobj1 obj2 obj1 ch_obj2
sobj1 obj3 ch_obj1 ch_obj3
I want resultset in format:
obj1 ch_obj1
obj1 ch_obj2
obj1 ch_obj3
obj2 ------
obj2 ------
obj3 ------
I am using the following query:
with recursive objects as (
select objectid
from object_masster
where objectid in (obj1, obj2, obj3)
union
select a.child_id
from object_child a a join objects b on a.objectid = b.objectid
)
select * from objects
It is returning me all the children for the above objects but not in the desired format.
The trick with recursive queries is that you need to store all of the data in the resultset of the seed bit and recursive bit of the union so you can have it to: A) perform the next lookup, B) display whatever you need when you select on the recursive CTE you've built.
So, for your requirements, we need to store the root node (the first objectid you are selecting from your master table), and then parent and child as we recursively select.
Also, because you want that root node to make it through to the end of all the recursive lookup, you need to keep selecting that through in your recursive bit of the union.
This will look something like:
WITH RECURSIVE objects AS (
SELECT objectid AS root, CAST(NULL AS VARCHAR(10)) AS parent, objectid AS child
FROM object_master
WHERE objectid IN (obj1, obj2, obj3)
UNION
SELECT b.root AS root, b.child AS parent, a.child_id AS child
FROM object_child a
INNER JOIN objects b
ON a.objectid = b.child
)
SELECT root, child FROM objects
I am trying to query two tables that are in 1-to-many relationship.
What I've done is create a View knowing that i might end up with multiple records for the first table.
My scenario is as follows: I have a table "Items" and table "Properties".
"Properties" table contains an ItemsId column, PropertyId, PropertyValueId columns.
"Items" table/object contains a list of "Properties".
How would I query that "View" such that, I want to get all "Items" records that have a combination of "PropertyId" & "PropertyValueId" values.
In other words something similar to:
WHERE
(PropertyId = #val1 AND PropertyValueId = #val2) OR
(PropertyId = #val3 AND PropertyValueId = #val4) OR
(PropertyId = #val5 AND PropertyValueId = #val6)
WHERE clause is just a loop over "Items.Properties" collection.
"Items" represents a table of Items being stored in the database. Each & every Item has some dynamic properties, one or more. That's why I have another table called "Properties". Properties table contains columns:
ItemId, PropertyId, PropertyValue
"Item" object has a collection of Properties/Values. Prop1:val1, Prop2:val2, etc ...
Thanks
I may not have understood your requirement (despite the update) - if this or any other answer doesn't solve the problem please add some sample data for Items, Properties and the output and then hopefully it would become clear.
If Items is a specification of the property name-value pairs that you need (and has nothing to do with ItemId on Properties which seems strange...)
select p.itemid
from properties p
where exists (select 1 from items i where i.propertyId = p.propertyId and i.propertyValueId = p.propertyValueId)
group by p.itemid
having count(distinct p.propertyid) = (select count(*) from items)
This returns a set of itemids that have one (and only one) property value for each property defined in items. You can put the items count into a variable if you want.
I would use a query like this:
SELECT ItemId
FROM ItemView
WHERE (PropertyId = #val1 AND PropertyValueId = #val2)
OR (PropertyId = #val3 AND PropertyValueId = #val4)
OR (PropertyId = #val5 AND PropertyValueId = #val6)
GROUP BY ItemId
HAVING COUNT(*) = 3
The WHERE clause is the same as in your question, it only allows a row to be selected if the row has a matching property. You only need to make sure additionally that the items obtained have all the properties in the filter, which is done in the above query with the help of the HAVING clause: you are requesting items with 3 specific properties, therefore the number of properties per item in your result set (COUNT(*)) should be equal to 3.
In a more general case, when the number of properties queried may be arbitrary, you should probably consider passing the arguments in the form of a table and join the view to it:
…
FROM ItemView v
INNER JOIN RequestedProperties r ON v.PropertyId = r.Id
AND v.PropertyValueId = r.ValueId
GROUP BY v.ItemId
HAVING COUNT(*) = (SELECT COUNT(*) FROM RequestedProperties)
How to set an object to null.
Ex:
my object samp contains three fileds
samp.field1,samp.field2.sampfield3
If i set samp:= null;
im getting errors is there a way to set the object value to null.
An sql database does not know about objects, it deals with rows in table.
To remove a row use DELETE :
e.g. :
DELETE FROM samp WHERE id = 12345;
DELETE FROM samp WHERE field1 = 'Delete Me';
The first example is typical to remove individual rows uing their primary key (id in this case)
The second example will remove a group of rows which have a speciic value for a field.