How to fetch data objects using web service in backbone.js - backbone.js

I have a relational database where two tables are linked by a key. Depending on a search criteria in the parent table, the web service will return a list consisting of child table records.
For example, if I have the parent table as "Version" with a column v_type and primary key v_id which references child table "Reference" with primary key ref_id and foreign key v_id. I need to fetch the list of records of table type "Reference".
How do I parse the list obtained?
How do I write the template and view?
A very simple example or syntax will be very helpful.

I think you can start by looking at Backbone-relational, that is where all database relational questions do get simple answers/solutions.

Related

ESRI parent/child relationship within the same table

Is it possible in ESRI to make a relationship within the same table or any other way to solve parent/child relationship? I have table “samples” and one sample can be split into multiple sub-samples which means any record(sample) can have one or multiple parents and opposite. But as parent and child represents the same thing they should be a member of the same table. Any ideas would be appreciated!
I have tried creating intermendiate table 2 relationship class
Relationship class 1:1 Simple where sample.id=intermediate.sample_id
Relationship class 1:M Simple, sample.id=intermediate.sample_initial_id
But it ended up that I have to delete the relationship record in intermediate table before deleting parent or child otherwise there will be written in intermediate table. Its not very comfortable and I don´t know how it would work in services.
One approach would be to use a self-join on the table. This involves creating a copy of the table and joining it back to itself using a foreign key to establish the parent-child relationship. In your case, you could create a "parent_id" field in the "samples" table that references the "id" field of the same table. Then, you can join the "samples" table to itself using the "parent_id" field to establish the parent-child relationship.
Another approach would be to use a hierarchical relationship class. This type of relationship class is designed to handle hierarchical data, such as parent-child relationships, and can be used to maintain relationships between records in the same table. In this case, you would create a hierarchical relationship class that defines the parent-child relationship between records in the "samples" table.

Unable to use the dimension table as a nested table in SQL server data tools

I have the following relationship set up between my fact table and dimension tables.
When trying to create a data mining structure, I had to choose the dimension table Dimension_Status as a nested table for the fact table as I'm trying to predict the probability of "TimelyResponse" in the fact table using the "IssuedVia" in the Dimension_Status table. But when trying to do so, I get the following error.
Dimension_Status table cannot be used as a nested table because it does not have a many-to-one relationship with the case table. You need to create a many-to-one relationship between the two tables in the data source file
What am I doing wrong here? Why am I getting this error though my dimension tables are maintaining a many to one relationship with the fact table? Please advice.
I could be completely missing the mark here (I haven't done a great deal of data-mining using SSAS), but from what I can tell nested tables are the "Many" side of a many-to-many relationship. From the MSDN article on Nested Tables it shows the "Products" table as being nested in the "Customer" table, because each Customer can have many Products:
In this diagram, the first table, which is the parent table, contains
information about customers, and associates a unique identifier for
each customer. The second table, the child table, contains the
purchases for each customer. The purchases in the child table are
related to the parent table by the unique identifier, the CustomerKey
column. The third table in the diagram shows the two tables combined.
A nested table is represented in the case table as a special column
that has a data type of TABLE. For any particular case row, this kind
of column contains selected rows from the child table that pertain to
the parent table.
So it looks like nested tables are not what you're after - unfortunately I'm not familiar enough with the SSA data mining tools to recommend the appropriate approach (unless switching them around and making the DimStatus table your Case table and Fact_CustomerComplaints your Nested table will work in your situation.)
To put it simply, your arrows are backwards.
Reverse the relationships so the tables you want to be nested are pointing to your Fact_ table.
Like so:

MSSQL and Entity framework syncing PK on multiple tables

I've been working with Entity framework in C# trying to figure out how to join two tables together. I found a reference here http://msdn.microsoft.com/en-us/data/jj715646.aspx on how to do this. Problem is, the two tables have PKs that are not in sync which seems to be a requirement. I've never had to worry about syncing PKs from two tables in a database before. I know I can turn off identity insert on one table but I see comments from numerous people that this is a very bad idea. If I'm not supposed to do this, then how do I accomplish syncing the PKs in each of the tables?
I have two tables in a database:
User
pkID (int)
FirstName (varchar)
LastName (varchar)
Email (varchar)
...
LockedFlags (locking fields in user from being edited)
pkID
fkUserID
bFirstName (bool)
bLastName (bool)
bEmail (bool)
I'm curious on why people thing that removing the identity insert on a table is a bad idea... if I'm relying on MSSQL to assign a PK then I could see an instance when I'm inserting a record into the database where the second table write could get a different value when dealing with multiple writes...
It sounds like you have orphaned rows in the LockedFlags table, like a row with a user ID that points to a user that has been deleted. Depending on how the relationship is setup it can also be true for the reverse.
If you have a entity where the 2 tables are combined into a single class, loading the entity set will query both tables and require matching pairs of rows.
Your LockedFlags probably has a User property which it is trying to load and cannot find in the user table.
Table options:
Note: I'm using MSSQL equivalent as I don't know MYSQL.
Comments regarding your data model:
I don't know how MYWSQL handles record locking but if it is anything like MSSQL, you do not have to worry about manually handling.
I would strongly suggest re-looking at your data model if you're going to use it as is. Just using a single table would be best if you really want to manually lock individual row fields?
Edit:
ALTER TABLE LockFlags ADD CONSTRAINT
FK_LockFlags_User FOREIGN KEY
(
UserID
) REFERENCES User
(
pkID
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO

Reading directly from the Doctrine Searchable index table

I've got a Doctrine table with the Searchable behavior enabled.
Whenever a record is created, an index is made in another table. I have a model called Entry and the behavior automatically created the table entry_index.
My question now is: How can I - without using the search(...) methods of my model use the data from this table?
I want to create a tag cloud of the words most used, and the data in the index table is exactly what I need.
Doctrine generates table EntryIndex that should be available from Doctrine::getTable('EntryIndex').
Additionally Entry has EntryIndex relation that refers to index table and EntryIndex has Entry relation. The relation is standard one-to-many (1-n) relation between Entry and EntryIndex.

Foreign key referencing composite table

I've got a table structure I'm not really certain of how to create the best way.
Basically I have two tables, tblSystemItems and tblClientItems. I have a third table that has a column that references an 'Item'. The problem is, this column needs to reference either a system item or a client item - it does not matter which. System items have keys in the 1..2^31 range while client items have keys in the range -1..-2^31, thus there will never be any collisions.
Whenever I query the items, I'm doing it through a view that does a UNION ALL between the contents of the two tables.
Thus, optimally, I'd like to make a foreign key reference the result of the view, since the view will always be the union of the two tables - while still keeping IDs unique. But I can't do this as I can't reference a view.
Now, I can just drop the foreign key, and all is well. However, I'd really like to have some referential checking and cascading delete/set null functionality. Is there any way to do this, besides triggers?
sorry for the late answer, I've been struck with a serious case of weekenditis.
As for utilizing a third table to include PKs from both client and system tables - I don't like that as that just overly complicates synchronization and still requires my app to know of the third table.
Another issue that has arisen is that I have a third table that needs to reference an item - either system or client, it doesn't matter. Having the tables separated basically means I need to have two columns, a ClientItemID and a SystemItemID, each having a constraint for each of their tables with nullability - rather ugly.
I ended up choosing a different solution. The whole issue was with easily synchronizing new system items into the tables without messing with client items, avoiding collisions and so forth.
I ended up creating just a single table, Items. Items has a bit column named "SystemItem" that defines, well, the obvious. In my development / system database, I've got the PK as an int identity(1,1). After the table has been created in the client database, the identity key is changed to (-1,-1). That means client items go in the negative while system items go in the positive.
For synchronizations I basically ignore anything with (SystemItem = 1) while synchronizing the rest using IDENTITY INSERT ON. Thus I'm able to synchronize while completely ignoring client items and avoiding collisions. I'm also able to reference just one "Items" table which covers both client and system items. The only thing to keep in mind is to fix the standard clustered key so it's descending to avoid all kinds of page restructuring when the client inserts new items (client updates vs system updates is like 99%/1%).
You can create a unique id (db generated - sequence, autoinc, etc) for the table that references items, and create two additional columns (tblSystemItemsFK and tblClientItemsFk) where you reference the system items and client items respectively - some databases allows you to have a foreign key that is nullable.
If you're using an ORM you can even easily distinguish client items and system items (this way you don't need to negative identifiers to prevent ID overlap) based on column information only.
With a little more bakcground/context it is probably easier to determine an optimal solution.
You probably need a table say tblItems that simply store all the primary keys of the two tables. Inserting items would require two steps to ensure that when an item is entered into the tblSystemItems table that the PK is entered into the tblItems table.
The third table then has a FK to tblItems. In a way tblItems is a parent of the other two items tables. To query for an Item it would be necessary to create a JOIN between tblItems, tblSystemItems and tblClientItems.
[EDIT-for comment below] If the tblSystemItems and tblClientItems control their own PK then you can still let them. You would probably insert into tblSystemItems first then insert into tblItems. When you implement an inheritance structure using a tool like Hibernate you end up with something like this.
Add a table called Items with a PK ItemiD, And a single column called ItemType = "System" or "Client" then have ClientItems table PK (named ClientItemId) and SystemItems PK (named SystemItemId) both also be FKs to Items.ItemId, (These relationships are zero to one relationships (0-1)
Then in your third table that references an item, just have it's FK constraint reference the itemId in this extra (Items) table...
If you are using stored procedures to implement inserts, just have the stored proc that inserts items insert a new record into the Items table first, and then, using the auto-generated PK value in that table insert the actual data record into either SystemItems or ClientItems (depending on which it is) as part of the same stored proc call, using the auto-generated (identity) value that the system inserted into the Items table ItemId column.
This is called "SubClassing"
I've been puzzling over your table design. I'm not certain that it is right. I realise that the third table may just be providing detail information, but I can't help thinking that the primary key is actually the one in your ITEM table and the FOREIGN keys are the ones in your system and client item tables. You'd then just need to do right outer joins from Item to the system and client item tables, and all constraints would work fine.
I have a similar situation in a database I'm using. I have a "candidate key" on each table that I call EntityID. Then, if there's a table that needs to refer to items in more than one of the other tables, I use EntityID to refer to that row. I do have an Entity table to cross reference everything (so that EntityID is the primary key of the Entity table, and all other EntityID's are FKs), but I don't find myself using the Entity table very often.

Resources