How to use more than one hierarchical separeted FK's in a table? - foreign-keys

I've got two tables that relate to one another in a 1:M relationship: parent and child.
I've constrained the parent_id column in the child table to match only parent's table id values, by using the Foreign Key constraint. Now I want a third table - called another_table - to have two FK columns that references the id column in the parent and child tables.
How can I restrict the child_id FK column in the third table, only to values from the child table that match parent_id value?
EDIT
E.G: As I mentioned above I've got three tables - parent, child and another_table. Their content looks like this:
SELECT * FROM public.parent
id name
1 A
2 B
3 C
SELECT * FROM public.child
id name parent_id
1 A1 1
2 A2 1
3 A3 1
4 B1 2
5 C1 3
6 C2 3
SELECT * FROM public.another_table
I want to find a way within the DB structure (at the mean time), to prevent from inserting or updating a value in the third table's child_id column, that do not comply with the child's table data.

Since the parent is linked to the child, the child has the parent link. You do not need to link both parent and child to your child's children. You only need to link the child's children to the child which already has the parent.
Parent
/\
child1 child2
/\
pc_child pc_child2

Related

Django how to include all columns from one table, but a only subset of columns in a different table, using tbl.only?

I want to join a child table to the parent table, and return all columns from the child table (child.*), but only specific columns from a parent table (parent.foo, parent.bar), using only but not defer.
Is there any syntax to issue a SQL similar to the following:
select child.*,
parent.foo, parent.bar
from child join parent on child.parent_id = parent.id
I do not want to use defer, because the parent table has even more columns than the child table.
I currently have to spell out every column that I want using only:
Child.objects.select_related('parent').only(
'id', 'name', 'creation_date',
'parent__foo', 'parent__bar'
).all()
But I would like to include all the columns from Child.

Can I create a link based on multiple columns in Siebel?

Our Siebel application has 2 tables, both of them sharing 4 text fields. I want to create a link, to show as a child BC all the records from the second table, having the same 4 values as the current record from the first table.
In SQL this could be easily done with something like this:
select *
from table1 t1
left join table2 t2 on (t1.a = t2.a and t1.b = t2.b and t1.c = t2.c and t1.d = t2.d)
where t1.row_id = '1-23456';
Can I build something similar in Siebel 7.8?
I thought creating a link based on any of the text fields (the one with the least repeating values), and then filter the 3 remaining fields in the child BC search spec, but... how do I reference the parent BC values in a search spec? (Without using profile attributes or calculated fields, which would impact too much on performance).
Note: I can't change the tables for this task, however the child BC will be created for this task and won't be used elsewhere.
You will have to use a link search spec. Links can have searchspec, for exactly this reason. Go to links and search for NOT NULL on the searshspec column to see vanilla examples. The link searschspec is always applied on the child bc, so to accesss fields from parent bc, use the ParentFieldValue function
example:
[Account Id] = ParentFieldValue ("Account Id")
on link "Account Product - CPG/CG SVP Product Baseline - for Adding Data"

Get selected element in QTreeView

I have a QTreeView which e.g. shows following structure (all in same column):
parent 1
- child 1
- child 2
- child 3
parent 2
parent 3
Now I make use of a signal currentChanged() to find out which of the elements is selected. But there I get back the same index value 1 for "parent 1" and "child 1" or 2 for "child 2" and "parent 2" - it seems the index always uses the relative row count. So how can I find out which element is selected?
Thanks!
The model index row and column number are relative to the parent model index. Use the QModelIndex::parent() method to get the parent index.

How to phrase sql query when selecting second table based on information on first table

I have two tables I would like to call, but I am not sure if it is possible to combine them into one query or I have to some how call 2 different queries.
Basically I have 2 tables:
1) item_table: name/id etc. + category ID
2) category_table: categoryID, categoryName, categoryParentID.
The parent categories are also inside the same table with their own name.
I would like to call on my details from item_table, as well as getting the name of the category, as well as the NAME of the parent category.
I know how to get the item_table data, plus the categoryName through an INNER JOIN. But can I use the same query to get the categoryParent's name?
If not, what would be the mist efficient way to do it? The rest of the code is in C++.
SELECT item_table.item_name, c1.name AS CatName, c2.name AS ParentCatName
FROM item_table join category_table c1 on item_table.categoryID=c1.categoryID
LEFT OUTER JOIN category_table c2 ON c2.categoryID = c1.categoryParentID
SQL Fiddle: here

vaadin: moving data from selected row of table1 to table2

I have two questions:
I have two tables, table1 and table2. I need to design an application in such a way that a selected row of table 1 when clicked should get displayed in table 2.
How do I call a custom table? Suppose I have a class Table with empty constructor and I will pass arguments like Table(pagination). It has to show the table with pagination,
Similarly, Table(lazyloading) has to show lazy loading table. Table(pagination, Lazy loading,search) must show all three properties.
What you have to do for nr 1 is that you attach a Clicklistener to your table1 and on a Clickevent you take the selected Object ni table1 and add it to table2. Also add an if to not add rows that already exist in table 2.
This is how you copy data
public void copydata(){
Object o = table1.getValue();
if(!table2.getItemIds().contains(o))
table2.addItem(o);
table2.setContainerDataSource(table2.getContainerDataSource());
}
When it comes to your second question I have no clue what you are talking about, but I looks like you want to extend the Table class in vaadin to get your own features.