I am tasked to create a dashboard for an e-commerce business, in general, using Laravel Filament. While designing the database I made sure to include the feature of adding variants. As a result, I came up with 4 tables:
product_options (Color, Size)
product_option_values (Blue,Large)
product_variants
product_option_value_variant (To support the many
to many relationship between product_option_values and
product_variants)
While creating the form I used the CheckBoxList (A filament component that returns an array of the option_value_id) to add the variants. And there I noticed that I am adding Color Blue Color Red and Size Large to one variant which made me realize that the relationship between options_values and variants is not a many to many relationship.
Here's a picture of the CheckBoxList that I used:
So, a variant can have many options but only one value to this option. What relationship is that?
$this->hasMany(Relation::class)->distinct();
Is there a way to check from DAX, which Power BI report a user is opening?
My problem is that I have a model with tables:
-Revenue.
-CostCenter.
I have RLS set up for two special users: I take their USERNAME(), and I give these 2 users access to a specific set of Cost Centers.
Now, I am creating a new PowerBI, I am trying to reutilize the same cube.
But, the access is based on another table named ‘Contract’, so these same two users shall have special access to a set of contracts.
Can I have a way of using 2 Power BIs, pointing to the same cube, and in one report they shall see CostCenters x,y,z and in the other Contracts a, b, c?
Or is it more convenient to just “copy paste” the entire cube (that is, have 2 different cubes) and do the RLS on each one. (I am also in doubt what is the preferred way in terms of maintenance).
My very first DM so be gentle..
Modeling a hierarchy with ERD as follows:
Responses are my facts. All the advice I've seen indicates creating a single dimension (say dim_event) and denormalizing event, department and organization into that dimension:
What if I KNOW that there will be future facts/reports that rely on an Organization dimension, or a Department dimension that do not involve this particular fact?
It makes more sense to me (from the OLTP world) to create individual dimensions for the major components and attach them to the fact. That way they could be reused as conformed dimensions.
This way for any updating dimension attributes there would be one dim table; if I had everything denormalized I could have org name in several dimension tables.
--Update--
As requested:
An "event" is an email campaign designed to gather response data from a specific subset of clients. They log in and we ask them a series of questions and score the answers.
The "response" is the set of scores we generate from the event.
So an "event" record may look like this:
name: '2019 test Event'
department: 'finance'
"response" records look something like this:
event: '2019 test Event'
retScore: 2190
balScore: 19.98
If your organization and department are tightly coupled (i.e. department implies organization as well), they should be denormalized and created as a single dimension. If department & organization do not have a hierarchical relationship, they would be separate dimensions.
Your Event would likely be a dim (degenerate) and a fact. The fact would point to the various dimensions that describe the Event and would contain the measures about what happened at the Event (retScore, balScore).
A good way to identify if you're dealing with a dim or a fact is to ask "What do I know before any thing happens?" I expect you'd know which orgs & depts are available. You may even know certain types of recurring events (blood drive, annual fundraiser), which could also be a separate dimension (event type). But you wouldn't have any details about a specific event, HR Fundraiser 2019 (fact), until one is scheduled.
A dimension represents the possibilities, but a fact record indicates something actually happens. My favorite analogy for this is a restaurant menu vs a restaurant order. The items on the menu can be referenced even if they've never been ordered. The menu is the dimension, the order is the fact.
Hope this helps.
I have a use case where I need to model reference data for e.g. different flavors of ice cream. Say I have 50 flavors of ice cream :-
20 attributes e.g. freezing-temp, creaminess will be shared across all flavors
every flavor of ice cream would have 20-30 attributes that will not be shared with other flavors e.g. :-
Strawberry ice cream might track tartness, fruit percentage etc.
Chocolate ice cream might track bitterness, cocoa level etc.
How would I model this data neatly in a database model, purely from a storage / retrieval point of view?
The options I can think of :-
One table per flavor. This will need 50 tables, and each table will have 20 columns that will overlap with each other, and another 20-30 attributes that will be unique to the flavor.
Pros : models the data of each flavor quite well
Cons : column overlap and large number of tables needed
One table for all flavors. This will only need 1 table, but will require 1000+ columns most of which would be empty.
Pros : models the data of ice cream in general, quite well
Cons : large number of columns and large amount of 'wasted' space
One key-value table for all flavors, with flavor Id, attribute name and attribute value.
Pros : simplest to create and insert data
Cons : harder to extract, not really a data model per se, difficult to form constraints for attributes, or for attributes related to other attributes
Never store a value in the wrong type.
Whatever design you choose, make sure that values are stored in their natural format. Use NUMBER, DATE, VARCHAR2, CLOB, XMLTYPE, CLOB (IS JSON), TIMESTAMP, etc. Trying to cram everything in a string will cause many problems. You lose validation, convenience, performance, and type safety.
For example, here is a common type safety problem. Imagine this simple query to find ice cream that is more than 25% fruit:
select *
from ice_cream_flavor_attribute
where attribute_name = 'Fruit Percentage'
and attribute_value > 25;
Do you see the bug? Do you see how the same query, with the same data, may work one day and fail the next with ORA-01722: invalid number?
It's difficult to write a query that forces Oracle to evaluate conditions in a specific order. Re-ordering the predicates won't help (99.9% of the time). Adding an inline view won't help (99.9% of the time). Using a CASE statement will work but not 100% of the time. Using hints will work but is tricky. Using an inline view and a ROWNUM is my preferred way of solving the problem but it looks odd and is difficult to understand.
If you must use an Entity Attribute Value model (and if you have more than 1000 attributes it may be unavoidable), at least use the right types.
Don't worry about space - a null column uses at most 1 byte.
Don't worry about complaints like "but then our queries are more complicated, we always need to know which column to use!" - realistically there is almost nothing useful you can do with a value without knowing its type. Every time you read or write a value you must already be thinking about the type.
I'd have one table with all the common attributes, then another for the non-shared attributes. For example:
CREATE TABLE ICE_CREAM_FLAVOR
(FLAVOR VARCHAR2(100) PRIMARY KEY,
FREEZING_TEMP NUMBER,
CREAMINESS NUMBER,
ETC VARCHAR2(25),
BLAH NUMBER);
CREATE TABLE ICE_CREAM_FLAVOR_ATTRIBUTE
(ID_ICF_ATTRIBUTE NUMBER, -- should be populated by an insert trigger
FLAVOR VARCHAR2(100)
NOT NULL
REFERENCES ICE_CREAM_FLAVOR(FLAVOR),
ATTRIBUTE_NAME VARCHAR2(25),
ATTRIBUTE_VALUE VARCHAR2(100));
Your mileage may vary.
Share and enjoy.
I would like to suggest, You can create 3 different tables.
Ice Cream Flavor: You can store all the flavors of ice cream. It will be icecream_flavor_master table. Let say if you have 50 flavors than 50 rows will create, like Strawberry,Chocolate etc.
Ice Cream Attributes: You can store all the attributes of ice cream. It will icecream_attribute_master table. Let say if you have 50 attributes than 50 rows will create, like tartness,bitterness,fruit percentage, cocoa level etc.
Ice Cream Flavor Attributes: You can store primary key of icecream_flavor_master and icecream_attribute_master in this table, to make the relation between flavor and attribute of icecream.
Let me know for further information.
You might be able to group flavors into classes of flavors, ones that share certain attributes. This lends itself to classes and subclasses that extend other classes.
If you want to do ER modeling on this, look up "generalization/specialization" on the web. Some websites will call this a feature of "Extended ER modeling" or EER.
If you want to design relational tables to implement the ER design, look into two patterns: Single Table Inheritance and Class Table Inheritance.
https://stackoverflow.com/tags/single-table-inheritance/info
https://stackoverflow.com/tags/class-table-inheritance/info
Also, look into Martin Fowler's treatment on this subject on the web, or in one of his textbooks.
What big vendors are doing for huge data in ECM (enterprise content management), where you have a quite similar scenario (many custom classes with custom attributes, some of them might be the same, having various types over attributes):
One key-value table for all flavors, with flavor Id, attribute name and attribute value.
They use one key-value table per type (string, number, date etc.).
For performance optimization, they allow to define dedicated tables for attributes, in order to keep index small and not crowded with other attributes.
Dedicated tables make sense for:
Massive usage (having many rows)
Bad histograms (like flags)
Otherwise Oracle index could be tricked, and full table access is the fastest access, which would be really bad.
So think early about performance when having huge amount of data.
I have a situation:
I have products that are in a CodeIgniter Cart custom store.
Each product has an ID associated with it, but also has options for it (sizes).
These sizes all have different prices. (We're talking about photos being sold at different print sizes).
Because CI Cart updates, adds and deletes based on the product ID inserted, I am not able to insert one product with 2 different sizes.
As of now, the only solution I can think of is to pass the ID to the cart as IMAGEID_OPTIONID so that it contains both IDs.
However, I thought there might be an easier, more uniform way of doing this?
Or a better solution than an ID that isn't (on it's own) associated with anything specific unless i explode it..?
I recently built a site that had these constraints. In short, you'll want to create a distinction between "products" and "product groups". Think of it as managing the most discrete data units. In reality, shirt X sized medium is actually a different thing than shirt X sized large...doubly so if you have prices that are built on these qualities (this becomes more realistic when you consider cloth patterns or colors).
So anyway, if you have a "groups" table, a "product_groups" table, and a "products" table, you can keep all of these ideas distinct. On your products table, you can have columns for "size" and "color" (and any other distinguishing property you can think of) and a column for "price". Alternatively, you can go even more hardcore and make separate pricing tables that match up prices to unique products (this would be especially useful if you want to keep track of historical prices and discounts).
Then in your cart you can simply attach product_ids to cart_ids and perform a couple of joins to determine what "group" this product is a part of, what pictures are in that group (or exist for that product), and so on. It's not a simple problem, but following this line of thought should help get you on the right path.
One last point: keeping track of unique products like this also makes inventory accounting much, much more straightforward.