I have ng-grid and columns in that I have field country id, but I want to print country name in cell. So how can I do that? - ng-grid

I have ng-grid. Inside that I have bind some columns which is firstname, last name, country, state city.
Actually in country, state, city columns I have stored IDs in table, but on the base of ID I want to print country name. How is this possible?

{ field: 'City', displayName: 'ישוב', cellTemplate: '<div> {{getCityName(row.getProperty(col.field))}}</div>' },

Related

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'}

Sort Primefaces DataTable column with two Columns names in sortBy attribute

I would like to sort a dataTable which has column named "CustomerName" which needs to be sorted based on Customer's FirstName & LastName.
So i'd like to pass value to sortBy attribute as shown below
sortBy="CustomerTable.FirstName,CustomerTable.LastName"
When i try this i get a parser error stating that String
I am able to sort a column with one table name & column name as input like shown below
sortBy="CustomerTable.CustomerNumber"
sortBy="CONCAT(CustomerTable.FirstName,' ',CustomerTable.LastName)"
This will sort the column in alphabetical order after concatenating the FirstName and LastName columns of CustomerTable

What to choose to use to determine the relationship?

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?

Totalling values with the same order name

I have table in mysql with columns "name" and "views". I want sum views from serial whose name is in "name" column and display list of serials with views by echo from the most popular.
I think you are looking for this query:
SELECT name, SUM(views) as total_views
FROM serial
GROUP BY name
ORDER BY total_views DESC

Compare two columns from two different tables

TableA: Personal_info (Name,DOB,Fname,add,......)
TableB: Company_Info (Name,DOB,join_dt,Qual,sal....)
I want to compare these two tables in such a way that it displays different DOB with same name (Date of birth).
thanks.
You should join the two tables on the Name field and not equal DOB:
SELECT Personal_Info.DOB, Company_Info.DOB, Name
FROM Personal_Info JOIN Company_Info ON Personal_Info.Name = Company_Info.Name
AND Personal_Info.DOB != Company_Info.DOB

Resources