What's the best practice to save all data from multiple step pages? - activerecord

I need help.
I have a web application in Yii2 with multiple pages step-by-step, that aggregate any data to one model. Want to know how to aggregate all data: with multiples AR models or in one AR-model with not-required columns. What's the best practice for it?
For example. I have a "Customer" ar-model. In first step i have "personal info" page with fields: first name, last name, etc. In second step i have another group of data, such as "contact info": email, phone etc.
What's the best practice for it: create one "Customer" AR-model with all not-required columns (phone, first_name, last_name, email) or create two AR-models, with required columns, such as CustomerPersonalInfo and CustomerContactInfo with related required columns.
Thank you very much for any help. Sorry for my language.

Related

How to access categories in Wix Database

I've been struggling to create a repeater which accesses specific information in my Wix data base. My question is a bit more complex than connecting the repeater to a column.
Rather, I want the repeater to access types of data within a column on the database. I have a column in the data base with an id, "category". For illustrative purposes, say the name of the data base is "store". I'm selling two different types of shirts. Some are casual, others formal. "category" has twenty iterations of both "formal" and "casual". If I create a repeater which accesses "category" and displays its text, I'll end up with a repeater forty iterations long. Instead, I want to parse out how many types of categories there are (in this case, two: "formal" and "casual") and only to display each category once-- a repeater which is only two iterations long.
(I know Wix has the ability of accessing how many types of information there are in column "category", I just don't know how to actualize on that ability. I know Wix has this ability because you can create a dynamic item page with a url of name "category". This will create a page for each category in "category". How do I do the same thing but for a repeater?)
One way to accomplish this is by using the Wix Data API Distinct query and then using the query result as the data for your repeater. This means you would not use the GUI connect to dataset, but the code in the page's IDE. Once the query returns, you can set the data property of the Repeater and then use the onItemReady() function for any further manipulation you may need.

Database: Storing multiple Types in single table or multiple intermediate tables for Delta Tables

Using Java and Oracle.
We need to update changes in Email, UserID of employee to third party.
Actual table is Employee and intermediate table we keep which we will use for comparison of changes before sending to third party.
Following are database designs coming in mind for intermediate table:
Only Single table:
EmployeeiD|Value|Type|UpdateDate
Value is userid or email, type will be 'email' or 'userid'. Update date is kept so to figure out that which of email or userid was different and update to third party.
Multiple Table:
Employee_EmailID
EmpId|EmailID|Updatedate
Employee_UserID
EmpId|UserID|Updatedate
Java flow will be:
Pick employee from actual table.
Pick employee from above intermediate table.
Compare differences. Update difference to third party.
Update above table with updated value and last update date.
Which one is consider as best way, single table approach or multiple table or is there any standard way to implement the same? There are 10,000 Employees in system.
Intermediate table is just storing Delta records i.e Records transferred to third party so that it can be compared next day.
Good database design has separate tables for different concepts. Using the same database column to hold different types of data will lead to code which is harder to understand, prone to data corruption and less performative.
You may think it's only two tables and a few tens of thousands of rows, so does it matter? But that is only your current requirement. What you choose now will set the template for what happens when (say) you need to add telephone numbers to the process.
Now in future if we get 5 more entities to update
Do you mean "entities", like say Customers rather than Employees? Or do you really mean "attributes" as in my example of Employee Telephone Number?
Generally speaking we have a separate table for distinct entities, and all the attributes of that entity are grouped at the same cardinality. To take your example, I would expect an Employee to have one UserID and one Email Address so I would design the table like this:
Employee_audit
EmpId|UserID|EmailID|Updatedate
That is, I have one record which stores the complete state of the Employee record at the Updatedate.
If we add a new entity, Customers then we have a new table. Simple. But a new attribute like Employee Phone Number offers a choice, because an employee can have more than one: work landline, mobile, fax, home, etc. So we could represent this in three ways: a child table with a type column, multiple child tables for each type, or as distinct columns on the Employee record.
For the main Employee table I would choose the separate table (or tables, depending on whether I'm shooting for 6NF). But for an audit table I would choose one record per Employee and pivot the phone numbers like this:
Employee_audit
EmpId|UserID|EmailID|Landline|Mobile|Fax|Home|Updatedate
The one thing I would never do is have a single table with type and value columns. It seems attractive because it means we could track additional entities without any further DDL. But in fact it becomes harder to re-assemble the complete state of an Employee at any given time with each attribute we add. Also it means the auditing process itself is more complicated (because it needs to determine which attributes have changed and whether it needs to audit the change) and more expensive (because changing three attributes on the same record entails inserting three audit records).

laravel define relation over multiple tables

I have a table customers with the fields id, name and so on.
One table doctors with the fields id, name.
Then there is one table subject_areas which has all subject areas which a doctor can have. The fields are id, text.
So, each doctor can have multiple subject areas. There is one pivot table doctor_subject which is a belongsToMany relation.
Here is my problem: A customer can have multiple doctors, but only for a specific subject area. I tried it with a new table customer_doctor with the fields id, customer_id and doctor_subject_id. But how do i map this in Eloquent?
Issue was in relation between tables. After chat clarification this came out as solution:
Html form is written in a way that customer first choose doctor, then depending on selection choose several of his available areas.
In that scenario customer needn't to be related to areas directly and should be related to areas only over relation with doctor.
Also as side note, if needed deeper relations, models on pivot tables could be created and used as well.

How to store different type and number of fields in one database table?

Hello everybody I'm making a "Bulletin board", like this: http://stena.kg/ad/post, I'm using Laravel 5.0, and don't know how to store different fields in database table, for example if I choose "Cars" category I should to fill Mark, Model, Fuel (etc fields for cars category), If I choose Flats category I should fill fields like Area, Number of rooms etc...How to organize all of this? I tried some ideas but nothing helped me(
Try to save data as json in table. Parse json format to string and save it in db, but it will cause many problems in future, so not recommend that solution. I recommend to store data in separate tabels, each one for category. For optimise process it is possible to create catregory table, and category_item table with fields like name, description and so on. Different category demands sp=ecific fields, so best solution is to create table per category.

How to list ID column from one table and then make a list of names from another column based on those IDs LINQ?

Ok, so the heading is not the best ever written, but here is the problem:
let's say I have three tables, for example "Services", "Clients" and "SomeTable" that stores IDs from both of the first two tables. Services table has two columns: "ServiceID" and "Name".
Now what I'm trying to do is to select all the "ServiceIDs" from "SomeTable" where "ClientID" is 10 and then after I get that list, I need the names of all those selected services from table "Services".
I hope you understand what I'm trying to manage here, I'll be more specific if needed.
Thank you.
var result=sometable
.Where(st=>st.ClientID==10)
.Join(services,a=>a.ServiceID,b=>b.ServiceId,(st,s) new {st=st,s=s})
.Select(x=>x.s.Name);

Resources