Laravel 5.2 - Can You Create A Relationship Between A Pivot Table And A Table It's Not Pivoting For? - laravel

I have a pivot table called user_store. It's used to establish a many to many relationship between the users table and the stores table and looks something like this:
user_id - int
store_id - int
user_age_range - string
I have another table called user_memberships. It's columns look like:
user_id - int
store_id - int
membership_cost - decimal
membership_expiration - date
I need to establish a relationship between the user_memberships table and the user_store pivot table using the user_id and store_id columns present in both tables.
How would I do this when the user_store table does not have its own model (since it's a pivot table)?

Related

When do we consider snowflaking a star schema?

In the below dimensional model, all the dimension table follows the star schema except the prod table, which is snowflaked and has prod_sub table as a child table. What is the strategical point to consider snowflaking a star schema?
Sales Table - Fact Table
Prod_id (fk)
Promo_id (fk)
store_id (fk)
Promo Table - Dimension Table
promo_id (pk)
Store Table - Dimension Table
store_id (pk)
Product Table - Dimension Table
Prod_id (pk)
prod_class_id (FK)
Prod_name
Prod_brand
Prod_sub Table- Dimension Table (snow flaked)
prod_class_id,
prod_class
prod_sub_class
prod_family
According to Kimball : Star Schema is the best way of designing a data model for reporting, You will get the best performance and also flexibility using such a model.
So no need to snowflake it.
Then your Product Table Dimension Table becomes :
Product Table - Dimension Table
Prod_id (pk)
Prod_name
Prod_brand
prod_class
prod_sub_class
prod_family

How to access the fields in the table in many-to-many intermediate tables?

How to access the fields in the table in many-to-many intermediate tables?
What kind of eloqunet builder is required to access the isAlternative field in the table named category_product?
Category table
categories
- id
- name
Product table
products
- id
- name
- price
CategoryProduct table
category_product
- category_id
- product_id
- isAlternative

relational database in eloquent laravel

hay i have table schema like this
table transaction_fueler
id | code | user_id |user_name| ref_code | area_name
table user_community
user_id | community_id
table user_community is pivot table from table users and community
in table transaction_fueler i want to get community_id from table user_community, depends on user_id* in **transaction_fueler how to get community_id depends on user_id in table transaction_fueler ??
i stuck this.. thanks
i recommend joining the two tables and select the columns you want:
$values = DB::table('transaction_fueler')
->join('user_community', 'user_community.user_id', '=', 'transaction_fueler.user_id')
->select('transaction_fueler.*', 'user_community.community_id')->get();

Laravel many to many pivot table accessor

I have a Users table and a Votes table and a vote_users table (many to many relationship)
In the vote_user table I have
user_id|vote_id| anonymous.
How can I change the user_id to -1 (only when sending to client) , if anonymous column has value TRUE ?

Get list of joined rows with DAX

I have Supplier dimension table has 1:n relationship with InvoiceDetail fact table. I would like to get the list of active suppliers like below SQL, but in DAX language:
SELECT [Id]
,[Name]
,[Code]
,[CountryIso]
FROM [Supplier] s
WHERE EXISTS (SELECT 1 FROM [InvoiceDetail] id WHERE s.id = id.SupplierId)
I am not sure how I can do on Measure with DAX
Assuming that an active supplier means that the supplier has an invoice against them and that your data looks something like this..
Invoice Table
Supplier Table
Creating a relationship between the two tables will in effect, 'join' the two tables.
You can then use invoice number field from the invoice table and the name/code/countryiso from the supplier table.
Example being:
The value are only being drawn from the invoice table, so you'll only see active Invoices.
If being an active supplier means having a true bool value, join the tables and add a report/page wide filter on that bool value.

Resources