I'm creating a kind of project management app which consists of 'jobs' and 'entities' (or tasks) within those jobs. As part of it I'm creating a todo list which should be unique to each user and I'm wondering what the best design is for the database?
Entities exist in their own collection and are related to jobs through a jobId field.
My initial thought was to structure it like:
Entity
Todos[]
User1
Todo1
Todo2
...
User2
...
I also have a users collection so would it better to store the todos there like:
User
Todos[]
Entity
Todo1
Todo2
...
Or some other method?? I think updating and deleting todos will be quite tricky..
Update
Option 3 - I could remove the user array and store the user on each todo object, like:
Entity
Todos[]
Todo{
User: John
Text: some todo
Done: false
Then filter all todos by a specific user. I will get some duplicate data (the user) but I don't think that's so bad..
Also when updating/deleting a todo is it safe to match it based on the text field or do I need to store a unique id on each todo?
I believe that your initial thought is the best of the two. In it, the User is referenced. In the second it looks like a user document with the todos in it. I think that is a little too much coupling, the first method being better decomposed and easier to modify/maintain as the reasons dictate in the future.
Related
I have a list of courses with a list of students. The idea is that a student can attend multiple courses.
The requirement is to return a unified list of courses-students where the "key" is like courseId + studentId. The GET result will be like:
courseId, courseName, studentId, studentName,...
My question is, which is the best approach to define this REST GET method. I have two solutions and any idea is welcome.
GET:api-name/v1/courses/students?version=5 - mening return from all courses the all students
GET:api-name/v1/courses-students?version=5 - in this case, is a dedicated method as courses-students
Any idea is welcome. Many thanks!
Update:
I was going to use solution 2.
Also, the remark that this relation could be considered a new resource is a strong argument.
I would bet on the second option, since you are exposing a new resource, which is the relationship between courses and students - even identifiable with that "key" relating the two IDs.
Going with this option may then allow you, for example, to find the new resource with the key, or filter this new resource with query string parameters (e.g. api-name/v1/courses-students?courseId=12,45&studentId=32,67), or request for students of an individual course (api-name/v1/courses/{courseId}/students), or for courses of an individual student (api-name/v1/students/{studentId}/courses).
There is a question with good answers on this topic here.
I'm new to Swift/CoreData and SQl databases. I have a CoreDatabase with over 7000 items. I want to create an entity (or any other way) to store how often a certain entry in the DB has been used. I need this in order to create a weighted sorting algorithm that suggests certain entries.
The catch is that I do not want to store this on the entries themselves, they need to remain generic in order for me to be able to update them every now and again via my own Node server. So all users have the same DB. Whenever the user picks one of the items it's counter increments by one. Whenever I query an item the frequency should come with it so I can perform a sorting algorithm on it.
I've been reading up on articles, it seems like this can be done, but none so far have been really useful. I've also looked a SQLite articles on this but haven't found what I was looking for.
I'm thinking something along these lines:
FrequencyList { Item_1 { ...7000 items....
item_1_freq : 0, ------------> frequency : 0,
item_2_freq : 12, name: "lala"
item_3_freq : 3 ...
... };
...
7000?!?!
};
Or would a separate 'meta' entity in a one-to-one relationship with it's respective Item be a good solution?
How can I tackle this?
In Core Data it would probably be better like this:
Put the selection in an entity with a count property, and have a relationship between the selection and the item. The Selection --> Item relationship could be to-one or to-many depending on your needs; I have it as to-many here but that might not be best in your case.
If you want to get the number of selections for an Item, use the value of selection.count. Update selection.count when a selection occurs.
A general parse.com relationship question really - using swift. I have a blogging app, for which there is a blog class, and a user class (along with a few others!) the blog class stores the associated user ID in a field for simplicity. Can I use includekey (or something similar) in a pfquery for the following;
firstly retrieve specific (or all) blog entries that match a criteria.
for each matching blog entry, check a field in the related user class for an option before returning the JSON list of entries
I suppose, sort of a subquery really, but wanted the whole thing to work in one pfquery if possible.
thanks!
Yes, you can do this with a relational query. The user stored in blog should be a pointer.
First create a query for the field in the user class, i.e.
userQuery.whereKey("age", greaterThan: 30)
(Do not execute this query)
Then, when adding constraints to your blog query, add
blogQuery.whereKey("user", matchesQuery: userQuery)
I'm just starting out with DDD and have built a repository pattern using EF code first which so far is working very well. Now say I have an aggregate root call Animal which has an entity called Status.
Now if I need to populate a drop down list with Status objects, or I need to replace the Status object in animal with a new one. How should I access the Status collection. In this case Status is not an aggregate root and only has meaning by association with Animal, it will have an identity though.
Should I either create a new Repository for Status by making it an aggregate root (it just one of many such things so this might get out of hand), or do I allow access the Status collection via the AnimalRepository with something like GetStatusByID or GetAllStatuses?
This same question could equally apply to value objects such as color, breed, sex etc.
This sort of stuff I'd treat as lookup/reference data; I've found this answer useful in the past: Loading a Value object in List or DropdownList, DDD
But basically I'd have a separate repository.
In my web app a user can assign muliple tags to products (like the tagging here on stackoverflow).
There are three tables: products, tags and products_tags to implement a many to many relationship.
My question is, how would you implement this with the Entity Framework (LINQ to SQL):
"Insert only a new tag in the tags table if it doesnt already exist there".
So before the insert i have to check first if a tag exists, whats the best way to accomplish this (best performance) ??
thanks for answers
Simple: The Tag should then be the user assigned key/PK of the entity/table.
If you have troubles synchronizing this with the database, I am sure there's something like (N)Hibernate's merge Method in EntityFramework.