Page 1 of 1
Lookup Fields pull same data, not unique to record
Posted: 2020-11-16 00:30
by bkerr
I hope I'm explaining this correctly as I'm new at this. I have a customer record and I have a tab for "trips", so I need to be able to see where they have been in the past, so I made the lookup fields to pull the information that I need. I tried to set the unique ID as the field to pull data, but then the other data only copies from the first record.
Screenshot 1 shows multiple trips history, but has the same data, Screenshot 2 shows multiple trips with unique data for customer. Am I coding something wrong?
Thanks
Re: Lookup Fields pull same data, not unique to record
Posted: 2020-11-16 00:49
by jsetzer
It seems you are referencing from a
customer record to two related
trip-records using 2x lookup in
customers-table + 2x 5 autofills in
customers table. This is called a non-normalized* data model which should be avoided for several reasons.
Recommendation
Instead of having n sets of fields in
customers table (n x (1 lookup + m autofills)) I recommend defining a normalized* model which has many advantages over non-normalized models and less problems with autofills.
customers
- id
- ...more fields, but all customer-related
trips
- id
- customer_id
lookup referencing customers table
- agent_id
lookup, referencing agents (or employees) table
- date
- destination_id
lookup, referencing destinations table
- cost
- vendor_id
lookup, referencing vendors table
- commission
- ...more fields, all trip-related
You should think it over other way round:
Not the
customer has to store two
trips, but every
trip belongs to exactly one
customer.
So, not the customer will hold the id's of two trips, but each trip (child) will hold the id of the related customer (parent).
You will be able to add as many trips as you like to each customer, not only two. This is much more flexible and scalable for future purposes.
* info about normalization:
https://en.wikipedia.org/wiki/Database_normalization
Re: Lookup Fields pull same data, not unique to record
Posted: 2020-11-16 19:36
by bkerr
Thanks, I will try and wrap my head around that and adjust the tables. Makes a lot of sense to be able to scale
Re: Lookup Fields pull same data, not unique to record
Posted: 2021-12-23 08:25
by jaddison
I have much the same problem but mine is a game of football. There is an away side and a home side. Both home and away fields lookup the same Teams table for selection. An auto update field will present the logo for the selected team. Trouble is the auto update field for the second selection presents the logo for the first selected team. Please help
John A
Re: Lookup Fields pull same data, not unique to record
Posted: 2021-12-23 20:25
by pbottcher
Hi,
I think this is currently not possible with AppGini.
But what you can do is to create a second table team_copy (copy of the team table). Instead of using the table directly, you can now remove that table via phpmyadmin or similar and create a view to the original team table.
So you will have
team table
team_copy = view to team table
Now you can use the lookup for home to the team table and the aufofil for the logo and use the lookup for the away to the team_copy view.
AppGini does not know about the view and will treat it like a normal table.
An other solution would be to create a team_copy table and use the hook -> TABLENAME_init function to sync the team table to the team_copy table.
Re: Lookup Fields pull same data, not unique to record
Posted: 2021-12-23 23:29
by jaddison
Hi pböttcher
I know why you have the Superman logo, brilliant. The view method works fantastic.
Thanks again
John A
Re: Lookup Fields pull same data, not unique to record
Posted: 2021-12-24 10:58
by pbottcher
Hi John,
thanks for the feedback.
Glad it works and I could help.