/    Sign up×
Community /Pin to ProfileBookmark

This is my a best practice, how should I approach this one question… it seems messy.

**Scenario**
I have a range of object types that I’m waiting to get user reviews on, it’ll be in the form of a textual summary. Each object type has a list of individual instances of the type. Each object type has it’s own table specific to it and each instances has a row in that table.

**Example**
Type: Cars
Car 1
Car 2
Car 3

Type: Buses
Bus 1
Bus 2
Bus 3

**What I want**
I’m trying to work out how to manage this in a database and from a administrative point of view. Given it’s the same principal for all object types (10 in total) I thought a centralized database table and admin panel would be easier than 10 versions.

I’m thinking a SQL table, let’s call it objectReviews

It would have columns, objectTypeId (1 = cars, 2 = buses), objectId (the index id of the individual object ).

**My Question / Issue**
This is a evolving review, a bit like a Wiki page but much smaller. If object type 2, instance 3 (3rd bus) has a review. What can I do when if a user needs to update it?

**Question / Ideas / Thoughts**

  • Should I have a history table, move the old one over to the history table and insert a new one?

  • How does this work for minor updates or updates which are the same? (I’m thinking user credits)

  • If a admin needed to ‘approve’ a change, how could you stop updates on top of an already pending update
  • Happy for anyones thoughts and opinion

    to post a comment
    PHP

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogMay 04.2022 — > @kiwis80#1643803 Each object type has it's own table specific to it and each instances has a row in that table.

    This sounds a bit too fragmented to me (but based on my limited understanding). I'd be more inclined to have a "type" table, an "object" table...and then think about the "reviews" table later. ;)

    So, type table might be something like the following (plus whatever other columns you need to flesh it out):
    [code=text]
    id name description
    -- ----- -----------------------------
    1 car Everyone knows what a car is
    2 bus Almost everyone knows what a bus is
    3 bike Human-powered 2-wheeled vehicle
    [/code]

    object table could be like:
    [code=text]
    id type_id name description
    -- ------- -------------- --------------------------
    1 3 Schwinn XYZ123 Some generic bicycle
    2 1 Porsche 911 Classic sports car
    [/code]

    Then as/when you need to add a type, it's just a new row in an existing table -- no need to add more tables. Reviews in your review table would just need a object_id column to point to the the specific object being reviewed, and then can join on the type table to determine what type of thing is being reviewed, so that you can adjust logic, output, whatever accordingly.

    If I needed to track history, I'd probably just (just?) timestamp each addition to the review table (with each entry probably having a key to the user writing the review as well as the object ID). Each review row might include some sort of status column that admins could use to reject it, or users could use to indicate it's still a draft, etc. Then when you want the review for the Porsche 911, say, it might be retrieved something like:
    [code=sql]
    select review.title, review.text, object.name, object.description, type.name
    from review
    inner join object on review.object_id = object.id
    inner join type on object.type_id = type.id
    where object.name = 'Porsche 911' and r.status = 'A' -- for Approved
    order by review.submit_time desc
    limit 1
    [/code]

    Or something like that, just trying to give some food for thought.
    ×

    Success!

    Help @kiwis spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.24,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...