How to establish a relationship between two tables? - core-data

I'm new to core data.
I have a data model, in which there are two tables and a 1-N relationship between them.
The application downloads all data from a service and saves the data in each table.
In addition, the tables are related and therefore want to do this:
a) Obtain all elements of the table2, which satisfies certain conditions.
b) For each element in table2, the identifier look table1 / save the table1´s id.
c) I get the item in Table 1 which meets the requirements ID.
d) I relate to Table 2 with 1.
I'm not capable for doing this. :(
I do not know if this method for make a relation between tables in this way is good or no.

This is sort of difficult to answer. If you think about Core Data as an SQL table you'll just get yourself into difficulty.
Core data isn't about joining and searching tables, it's about an object graph. An object has relationships to another object which has an inverse relationship to the other object. Essentially, what you should be looking to do is:
This is a fetch request of the entity which you are storing in table 2 subject to a predicate which defines your conditions.
You don't actually deal with ids directly in Core Data. You hardly ever deal with the keys directly.
Step 1 returned a collection of objects, and you can run a further predicate on this to filter it.
That is what the inverse relationship is for.
I know this doesn't answer your actual question. I'm trying to get you to think of your Core Data store as a collection of objects related to each other rather than as a bunch of linked tables.

Related

Join a table with multiple other tables on a shared key column with TypeORM

I'm trying to create a table that supports statistics for different content types. I'd like to have the Statistics model have a JoinId and a ServiceTypeId (the differentiator column basically).
I'm a bit uncertain on how to do this with TypeORM as I've generally only joined tables to specific other known tables. I am guessing I would just make a JoinId and populate that manually and in my repositories look at the ServiceTypeId to determine which table to join the JoinId on?
If so as a follow up, is it possible to foreign key the other sides back to the JoinId? I would imagine so, again just newish to doing this.
Thank you!

Excel 2016 Relationship

Goal
Create a working relationship between my Category Sales and Voids PivotTables so I can leverage one slicer for all data.
Background
Using two PowerQueries, I pull in data from SQL to Excel. Because Sales and Voids have DateStamp and StoreID columns in common, I essentially concatenate these in the SQL query to create an ID. For example:
select concat(StoreID,convert(int,DateStamp)) as ID, DateStamp, StoreID, Category, Sales from...
select concat(StoreID,convert(int,DateStamp)) as ID, DateStamp, StoreID, Voids from...
This is a one-to-many relationship between the two (Sales --> Voids)
Problem
Despite creating the relationship in Excel (through Manage Relationships, as PowerPivot is not available) I can't get it to apply and Excel tells me relationships between tables may be needed. I've no idea what I'm doing wrong.
Workaround
The only workaround I can think of is to take the void value for a given day and divide by the number of categories that have sales, then just do a join to create one table that I pull into Excel. It would technically work for my application, but I'd love to know why the relationship isn't working.
Thanks.
The answer is to export your data into the data model so that you can use power pivot, PLUS a export another power query (or several) into the data model that is a deduplicated table of keys.
Then, in the data model editor, set up the data relationships so that there is a one to many relationship between your deduplicated key table(s) and the "actual data".
Then, in a power pivot, use those "key" tables as much as possible, maybe even to the ruthless ideal(1) of using ONLY key tables in your primary row and column headers, and if you have a second level of categorization then a deduplicated table of primary to secondary, and so on, then using the real data tables only in the body of your power pivot.
(1) - Keep in mind that this is just an ideal I'm just explaining to help you understand and maybe start moving towards as much as actually makes sense. As with most things, in reality, the ideal is almost never worth reaching because there are other factors (like your own patience and time).

PowerBi desktop

I have 2 tables I am trying to create a relationship with in power bi. Both tables have the same values for example:
Table1 has location and Table2 has Location however the location is different. Every time I try to connect them say I need a unique value. Can someone please help me so I can connect them together?
Here is a passage from documentation regarding relationships in Power BI (Create and manage relationships in Power BI Desktop. In short, one of the tables you choose for the relationship should have unique values in the join column. So far in Power BI, you can define 1:*, 1:1 and *:1 relationship.
BlockquoteNote that you'll see an error that states One of the columns must have unique values if none of the tables selected for the relationship has unique values. At least one table in a relationship must have a distinct, unique list of key values, which is a common requirement for all relational database technologies.
If you encounter that error, there are a couple ways to fix the issue:
Use "Remove Duplicate Rows" to create a column with unique values. The drawback to this approach is that you will lose information when duplicate rows are removed, and often a key (row) is duplicated for good reason.
Add an intermediary table made of the list of distinct key values to the model, which will then be linked to both original columns in the relationship.
One of your table has to have unique values in Location (Primary Key) while the other can have duplicate values in Location (Foreign Key). Plus, the table with duplicates (the fact normally) must have values that are present in the other table (in the dimension).
In my opinion, to match your needs, you hshould add all the possible location in the table which would have unique values (the dimension).
I hope I made myself clear.

How we can do CRUD operations on complex data models in Cassandra?

How we can do CRUD operations on complex data models in Cassandra?
I have a project using NOSQL.
I have a column family for my customers.
The column family has just "id" at first.
Then it will be updated by altering new columns.
Count and type of columns for each customer could be different.
Also, each column can include sub columns with ids again and it would be altered, too. So, they should be indexed. And documents are not useful for this issue.
I've read about NOSQL, and I've decided to use Cassandra. I will be thankful if you would answer this questions:
Is the above that possible?
How we can create and use CRUD operations on this column family?
If the answer of last question is true, what is the type of result of a query?
It will return some rows for each primary key (id)?
How we can manage that, to access a table like with no redundancy? because I don't now this summarizing should be manage in DBside or in code side.
Thank you for your help.

Cassandra many-to-many relationship modeling options

In this article the author illustrates several options for modeling many-to-many relationship in Cassandra. I would like to get some more clarifications on two of them:
Why option 4 would take more space? It seems like you are just "appending" Item_by_user to User column space.
Also, in option 4, how can you define composite columns as the author suggests? It seems like you have two groups of columns: 1) Name, Email and 2) Likes whereas the latter is wide(?). What would be the CQL code that defines Name, Email and wide columns for Likes for the User table?
Thanks.
The following images are taken form the article mentioned above:
As far as first question goes it looks to me that it will take same amount of space only one row per user and per item less because you keep everything in single row.
As for second question you can take a look at static columns (here is cql documentation). Basically it is a way to define column which will be shared by all values in one row (user details in user table and item details in items table) and you can update value only by using partitioning key.
Second solution can be to model which items user liked as map type (here is map documentation) and same thing goes to items (create a map of users which liked that item).
I suggest you to get more information about Data modeling in Cassandra. I've read A Big Data Modeling Methodology for Apache Cassandra and Basic Rules of Cassandra Data Modeling as useful articles in this case. They will help you understanding about modelling the tables based on your queries (Query-Driven methodology) and data duplication and its advantages/disadvantages.

Resources