What to choose to use to determine the relationship? - laravel

I have 3 tables:
table city (500 000 records)
table post (A city can have many posts)
table post_text (To store the text of the post)
table city has fields ID, NAME
table post has fields ID, CITY_ID, POST_ID
table post_text has fields TITLE, TEXT
What to use?
Polymorphic? Through? Something else?

Related

NIFI - How to insert distinct data from the flow and refer to that data ID in other places

I'm trying to learn NIFI so this is all new to me, I used to work with Talend and I have hard time translating to NIFI. So the main idea: For example is I have two tables in Postgresql
Table CITY :
ID (auto generated), city_name
Table PERSON :
ID (auto generated), first_name, last_name, city_id
and I have a CSV file :
first_name, last_name, city_name
Can you please explain how I can insert in tow tables from one flowfile and refer in the table PERSON to the ID of the city not the name from the table CITY.
Thank you
you could use LookupRecord to enrich each record with city id and split input in two files: matched/unmatched.
for matched you have to execute simple insert into PERSON table - because city id was found.
for unmatched you have to generate insert/upsert into CITY table and then route all those records to lookup record again.
or you could insert everything as is into temp table with structure that matches your CSV.
and then execute 2 simple sql statements:
populate missing cities from temp table
insert into person from temp table with lookup city id on the level of SQL server

Keep track of quantity and some columns in multiple tables

I'm trying to build a farm management app with Laravel and I need help with my database schema. Here are some of my tables
users (id, name)
products (id, trade_name, state, category_id)
expenses (id, category_id)
activities (id, equipment_id)
equipment (id, name, type)
Equipment can either be a tractor or implement. For tractors I want to have the following columns total_distance_traveled and a fuel_quantity
Product can be fertilizers, Insecticide, Herbicides and their state can either be liquid or solid and I want to to keep track of quantity of my products as well (quantity is in liters or kilograms)
I'm not sure if it's a good idea to include the total_distance_traveled and fuel_quantity in the equipment table and a quantity column in the products table
I've thought of creating a new stocks table and have a stockable_id, and stockable_type but that would only work for quantity since it's kind of a common column between products and equipment tables
I'ld like to keep track of total_distance_traveled, fuel_quantity for the equipment table and quantity for products table. e.g. when the total_distance_traveled is changed I'd like to know when that happened so I can have logs of my activities over time
You can create a stock table if you know that this table will only use for product and equipements:
id
stockable_id
stockable_type
quantity
total_distance_traveled // nullable as they have value only when item will be tractor,
fuel_quantity // nullable as they have value only when item will be tractor,
but for same table or if you think there can come other data too then a you can have a json column in which you can save extra attributes for specific item
id
stockable_id
stockable_type
quantity
sepecific_attributes //json where you can save any additional values based on your product
"{'total_distance_traveled':'100','fuel_quantity':20,'some_other_info':'value'}

Lavavel Eloquent: Relationships with 5 table

I have an app consisting of these tables
users
id
name
user_location
id
user_id
cities_id
cities
id
state_id
country_id
name
states
id
country_id
name
countries
id
name
Then how to get relationship this five table?
you have to create a many-to-many relationship between tables and use pivot table to show the relationship between table rows using foreignId

laravel join 3 table belongtomany

i have 3 tables and 1 tables pivot with 3 foreign keys , i want to show all artists name with theirs job for one media but i dont have any idea how about joinning those 3 tables
Media table: media_id , media_title
artist table: artist_id, artist_name
job table: job_id, job_name
pivot table: media_id, artist_id, job_id
I have tried to do with belongsToMany between them but no result, only show the artists name but can not get theirs job name for each
Thank you to much!
Can you give the relation between these tables?
I didn't really know what you want, but try this.
\DB::table('media_artist_job')
->join('media','media.media_id','=','media_artist_job.media_id')
->join('job','job.job_id','=','media_artist_job.job_id')
->join('artist','artist.artist_id','=','media_artist_job.artist_id')
->select([
'media.medial_title',
'job.job_name',
'artist.artist_name'
])->where('media.media_id',/*The media id you want to retrieve*/)->get();
Hope it help!

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