Simple Database Schema for a tech blog - database

I am building a simple tech blog and this is my database.
Because I don't really have a lot of experience I am looking to get some feedback if its an OK schema.
I will have 5 categories: Computer, mobile , laptop , tablet and General.
For users I will only have an admin to begin with and maybe I will add users later.
User will only be able to comment/share on the posts nothing more.
Only admins will be able to create posts etc.
Guests will only be able to browse the site and share posts.
I would like to add a feature to be able to count how many shares have been made for a specific post but later.
Also I might add sub categories to each category (for this I think that I need another table to track those).
Any help is appreciated, thanks in advance.

In my view, you should add a comments table; in your database a Post can have only one comment.
Comments should have this fields at minimum: id, body, post_id, user_id, because they belong to a Post and to a User.
In the posts table add fields: user_id and category_id because each post belongs to a User and to a Category; and remove the comment field because a post can have many comments.

Related

I have one contact in SF that works for one customer, but is now helping with another customer...how do I add her to the second customer's contacts?

I have a contact in SalesForce, she works for a PE group, and is attached to one customer, but is also helping answer questions for another customer. I tried to add her in the second customer's contacts, and it said she was a duplicate, but I can't figure out how to attach her to both accounts. Any direction on where I can learn to do that? Thank you!!
Contacts can be connected to accounts directly (parent-child, via Contact.AccountId lookup) and indirectly (many-to-many, AccountContactRelation). It's useful when contact has multiple functions, for example being Director in 1 company and VP of Sales in another.Check the page layout, you might have to add a related list.
https://trailhead.salesforce.com/en/content/learn/modules/accounts_contacts_lightning_experience/understand-account-and-contact-relationships-lightning might be a good start

sonata admin one-to-many and many-to-one display list

I have a project about nurse and patients. Nurse goes around and visits patients. The problem that I'm facing is that the nurse wants to see a list of all the visits they did for a patient.
I do have two admin pages, one is the patients admin (allows to create/edit patients) and another one that allows to log visits. Within the visit you select the patient. From the patient list, how can I list all of the visits a nurse did for a patient? and further more, allow to click an add button to log a new visit.
I don't have code to show, but if any of you can point to some documentation, or sample code, will be much appreciated.
On the patient edit page you could do the following. Assuming your entity is called something like VisitLogs. You can add the following to configureFormFields
$formMapper->Add('VisitLogs', 'sonata_type_collection' ['type_options' => ['btn_add' => true]], ['inline' => 'table', 'edit' => 'inline']);
This should display a table with the Visitlogs based on the patients (if the ORM is correctly setup) and shows a add new button.
I hope this somewhat helps you a little bit further. More information.
Note This is for the one-to-many relation. I'm guessing for the many-to-one relation you should use sonata_type_model not sure about that though.

Multiple datasources for one model in CakePHP

I have a very interesting problem in relation to CakePHP. I have a client that is currently selling products on eBay, and wants to start selling products on their own website as well. There would, then, be two separate sales avenues: (1) eBay, and (2) website.
However, they do want to have a seamless website experience for their customers. Basically, they want their current eBay sites to be categories within their current website, and their current eBay auction items to be searchable on their website.
A simple CakePHP website would have two tables: products and categories, with the simple table relation of "products belongsTo categories" and "categories hasMany products". How would I then add in the eBay categories and products? Basically, I want the http://site/products/index to return a list of ALL products, both in the products table and on eBay. I want http://site/categories/index to return a list of all defined categories in the categories table plus the categories items are listed in on eBay.
eBay has a very good pretty much real-time request query API, so I've been thinking about an option to do this, but am wondering if there is a better way... I don't think this option would work very well with PaginatorComponent...
Method:
(1) In beforeFind, capture the request parameters and save to a persistent variable
(2) In afterFind, make a request to the eBay API based on the request parameters, then manually add the results to the $results array.
Again, I think this would work for basic find operations, but I'm not sure this would work with pagination because I'm not sure how to deal with, say, a 20 item page limit (i.e. How do I deal with a page 2 when only 18 items from the database were on page 1, and now on page 2 I need to start at 19 instead of 21 from the database?)
Is there a CakePHP syntax that I'm overlooking here, or do I just start working on coding for all of these eventualities?
I'm coding on a CakePHP 2.6.0 platform.
Thanks so much for your help!
One possible approach would be to read all the products from each datasource, sort them in memory and paginate from there. The number of products would of course play a major role here.
A second one, if the number of products does not change too often, would involve a background process to retrieve their ID, and the most essential data, from eBay and write them in the common Product table, flagging the rows created.
Then Paginator can then show your results, but other fast-changing data can be retrieved on-the-fly from eBay for the flagged products while composing the page.

Database design for like/love relations

I know this might have been asked quite a few times, however I can not find any suitable solution for my problem.
I am implementing database where I have users and articles.
Now the article can be either liked or loved by any of the user.
And here comes the problem, I have to return json that contains list of all articles extended by two fields, liked and loved, because queries are gonna be connected to users.
So liked and loved might be true or false.
I thought about creating two different tables Liked & Loved where I would keep article_id - user_id and if that record exists that means user liked/loved particular article. However I am not quite sure if thats the correct way, nor I have any idea how would I build such query.
If it is important I am using postgresql together with ormlite.
Thanks for any ideas.
If I have understand your question you are basically describing an M-N relationship. A user likes/loves N articles and an article is liked/loved by M users. Such relationships are implemented via a third table that stores the association of users and articles.
You could create a table UserPreferences that links user_id and article_id and has extra columns to indicate if he liked/loved the article.
I can't tell you more about the schema since I don't know if you have other degrees about the preferences (hated, indifferent, confused etc)

check database design for a blog application

I am creating a blog application - where multiple users can publish, share and like blogs.
I've created an outline of the database but I am not sure if its the right way. I do not understand how to go about foreign key inspite of reading about it.
Can someone help me in solving these issues. Some questions that are in my mind are :-
- should the articles(blogs) details be stored in both 'Table Articles' and 'Table Share' at the time a user publishes an article. Will this help me in writing a php script in showing only the latest and shared articles on top of the page
- should articleid be stored in all tables?
Following is an outline of my database
Users
Table users
-userid
-email
-name
-password
-date_of_registration
Articles
Articles have a title and a description. Later I have plans to add images, but not now. A user can post an article after registration or logging in. Latest articles are shown on top of the page (along with shared articles).
Table Articles
-articleid
-userid
-title
-description
-datetime
Comments
Users should be able to comment on articles from other users + the person who posted should also be able to comment
Table comments
-commentid
-articleid
-userid
-comment
-datetime
Share
Users should be able to share articles they like. The person who posted an article cannot share it again. If an article has been shared it should come on top of all articles (along with the latest articles).
Table share
-articleid
-userid (the person who shared it)
-datetime
Like
Users should be able to like any article.
Table Like
-articleid
-userid (the person who clicked on the like button)
make sure you hash the user password and store a salt.
pick a common date naming scheme. "action"_at is a good one. For example, "registered_at" or "created_at". you should use underscores between words for maximum compatibility and legibility.
are you sure a user needs to login to comment? many blog systems let people comment w only an email address. No comment threads allowed?
you could add a "created_at" field to the like table. make sure you have a primary key on both article_id and user_id
How does sharing work? With whom are they sharing?
Otherwise, a good start!

Resources