get last record ID after insert Joomla 3 component - model-view-controller

I am writing a Joomla 3 component and new to the Joomla framework.
I need to insert data into two tables.
the logic follows
insert form data into table after submit
retrieve data for next insert ( i can do this and i have the data array )
insert data from array into second table with the PK of the first insert from step 1.These tables are related by 1-M
return the user back to where they came from with success.
I think i have to override the save method in my model to do this but i don't understand how to get the pk of the first save to use with the 2nd
Due to my lack of understanding I am not sure of best practice in this situation.
after reading there is a postSaveHook() method but I am do not understand how to access the data as it returns void
If i copy the Joomla parent save Method and override in the model it will return Boolean therefore i don't no how to access the last PK from the first insert / save.
thanks in advance for any advice.

Related

Readeonly property in kendo mvc project, and not work when sorting or filtering this column

I have two table in my database.
first has a id and description and second table has a id, description and first table key, i create a relation between this. after that i create a readonly property in models of second table and get the description of first table by query. i save 100 row of data in second table and 10000 in first table, and each 100 row of first table for one of the row of second table. now when i sort or filter my kendo grid on this column , this take a long time to load! i test this by a more data and see this is not work! i know this in controller whit out read only property but i want to say me a way to use readonly property!! please guide me.
Your question is a little vague but if I understand correctly, it seems you are having problems dealing with large datasets, you may want to look into using serverFiltering and serverSorting.
Not sure if you have implemented your grid through Razor (.cshtml) or client (.js) however these links should get you on the right track.
A few more tutorial links:
Razor
Javascript

Insert data into multiples tables

I have an excel file file that some data need to be inserted into Table1 and some other data into Table2 or Table3.
I Already have my routes,models, controllers for each table.
As I have to do one function to insert data into all tables, I don't know if I need to do it inside a Model. Also I don't know how to do it, how designate the right data to the right table.
Edit: More specific
I have a file input and a button inside my view. When I select the excel file with the input and press the button I need to read the data AND insert that data into my database. The problem here is that this data will go to different tables. I would know solve this if all data would go to a single table, but I have no idea how to divide the data to separte tables.
Should I call a function from controller inside the view ? If so which Controller use ? Or maybe a function from model, but again which Model should I use ? Since each table has it's own Model.
Do I need to use JQuery to make an Ajax then direct it to a certain route so that route would call a Controller's function that would make the inserts?
I Dont think so because all data manipulation should be inside a View, right ?

breeze.js insert parent/child with identity

Simple parent/child scenario like Order and OrderLineItems. I am inserting a new Order, the OrderID is an identity column (sql server). I'm also inserting OrderLineItems in the same SaveChanges transaction. I need to get the new OrderID into the OrderLineItems, but not sure how to do it. I have the appropriate FK relationships setup properly. When I save, I get an error that OrderID is a required field in OrderLineItems.
Will I have to split this out into 2 server calls? First to insert the Order, which will return the OrderID. And then another to insert the OrderLineItems?
The Breeze documentation discusses this topic (key generation) at several points including but not limited to: http://www.breezejs.com/documentation/save-changes, http://www.breezejs.com/documentation/extending-entities and http://www.breezejs.com/documentation/add-new-entity.
The basic idea idea is that providing that your model and metadata are set up properly, breeze can assign a temporary id in place of the identity column for use in linking your order and orderlineitem entities prior to being saved. As part of the save process, Breeze updates these temporary keys to their "real" key values and updates the local cache as well upon successful completion of the save.

Grails update html table ajax insert with message

I'm come from a .net background to grails. I got a form for user to insert, and a html table with the list of records. Once user insert a new record, how do I update the html table with the record and display a message - e.g. company inserted?
Create a domain class for inserting your records, with whatever properties you need. Read Creating domain class and Grails GORM
Once the user submits your form insert the necessary values as a record into this. For getting the entire list of records you can call the list() method on your domain-class. Send the entire list of records to the client side as the response of the action / render as a model. See render. Update your html table using these new records.
For the status part, you may want to do the insert operations in a try-catch block and render a status a message accordingly.

TableAdapter to return ONLY selected columns? (VS2008)

(VS2008) I'm trying to configure a TableAdapter in a Typed DataSet to return only a certain subset of columns from the main schema of the table on which it is based, but it always returns the entire schema (all columns) with blank values in the columns I have omitted.
The TableAdpater has the default Fill and GetData() methods that come from the wizard, which contain every column in the table, which is fine. I then added a new parameterized query method called GetActiveJobsByCustNo(CustNo), and I only included a few columns in the SQL query that I actually want to be in this table view.
But, again, it returns all the columns in the master table schema, with empty values for the columns I omitted.
The reason I am wanting this, is so I can just get a few columns back to use that table view with AutoGenerateColumns in an ASP.NET GridView. With it giving me back EVERY column i nthe schema, my presentation GridView contains way more columns that I want to show th user. And, I want to avoid have to declare the columns in the GridView.
When you add a new query to a given TableAdapter, it is going to assume the schema in which it is attached to, which is why you are getting blank values for the columns you don't want.
Since you mentioned having already created the procedure, what you need to do is use the Server Explorer to connect to the database and simply drag that stored procedure over into your XSD work area. What this will do is create a separate QueryAdapter that will have just the columns you specified (still strongly typed) and you can bind/interact with your GridView using that QueryAdapter instead.
Is the strongly typed dataset used in another query that returns all the rows from the table?
What you could do is create a dataview using the strongly typed dataset and expose a data table for your DataGridView.
I'm not sure what your requirements are totally, but this example should help you:
DataView dv = new DataView(ds.<Your_Table>);
// This will create a new data table with the same name,
// But with only two columns from the original table.
// This could then be bound to your data grid.
DataTable dt = dv.ToTable(false,
ds.<Your_Table>.<Your_Column1Column>.ColumnName,
ds.<Your_Table>.<Your_Column1Column>.ColumnName);
Just delete the columns you don't want at run-time before you bind to your Gridview. The underlying class is still just a DataTable after all.

Resources