Zend tableGateway Model Delete Query with Multiple IDs - zend-framework2

I want to delete multiple rows by TableGateway like below SQL
Delete from table where id in (1,2,5,6) - CSV of multiple ids.

See documentation at https://docs.zendframework.com/zend-db/table-gateway/
Build a Where object to pass as parameter :
$where = new Where();
$where->in('id', [1,2,5,6]);

Related

Table initialization in Zend framework 2

i am new to the Zend Framework 2.Any body can tell me that where i can initialize the tb table in ZF2 model? For example i want to select all the records form the user table in FZ2 model.
Regards,
Tauqeer
$db = $this->db;
$select = $this->db->select(false)
->from('user');
Try this one
refer this url http://framework.zend.com/manual/1.12/en/zend.db.select.html

zf2 - join using a using Zend\Db\TableGateway\TableGateway;

I want to do a simple join using zf2 selecting fields from the first and second table, but I get an error ('Statement could not be executed') when I try to put an array of fields into the columns method.
public function fetchAll()
{
$resultSet = $this->tableGateway->select(function (Select $select) {
$select->columns();// ->with params gives an 'Statement could not be executed'
$select->join(array('t2' => 'categories'), 'table1.idCategory = t2.id');
$select->order('dateTime DESC')->limit(100);
});
...
}
You will need to make sure the dateTime/id fields are in the column list you provide.
If you dump out the exception ($e->getTraceAsString()) you will get some more information about what is causing your error.
Either comment this statement Or add atleast one valid 'column' name in array (table column/field name).
$select->columns(array('column_one', 'column_two', 'column_N'));
A blank $select->columns(); statement generates sql query something like SELECT FROM table_name which results in error.
When you comment this statement, it generates sql query like SELECT * FROM table_name
and if you pass column names, asterisk replaced by them.

Creating Drop down list for a column which is defined as an Int in the SQL database - jqGrid ASP.NET MVC

I am using Entity Framework Database First approach in ASP.NET MVC.
I have created models from an existing database and everything works fine.
I am using jqGrid and trying to create a drop down list for a column which is defined as an Int in the database.
In the database, the values are either 0 or 1, so in the dropdown list I will have to show two values such as "Import" or "Export" based on whether it is 0 or 1.
Would I be able to handle this scenario in the jqGrid?
Please post any suggestions if you have!
I think you can handle this thing in colModal itself. there's is one option editOption you can specify with you colModal and based on the value you are getting from data you can specfy the text property of that column
In this case, the data for the grid should contain “One” or “Two” to be set in the column myname.
Now, with this setting
<script>
jQuery("#grid_id").jqGrid({
...
colModel : [ {name:'myname', edittype:'select', formatter:'select', editoptions:{value:"1:One;2:Two"}} ... ]
...
});
</script>
the data should contain the keys (“1” or “2”), but the value (“One”, or “Two”) will be displayed in the grid.
check this link for further help. You will get your answer. Because you didn't post your code(atleast you should have done that for ur that particular column) i can not say you are implementing the same way.

Adding new data to DB when using 2 tables

I am new to mvc and mvc 3 , I have a db that contain a company table (string id =as the company name )
And a table tourism that contain same info I would like to be able to add data to the tourism table , while selecting a company from the list (that came from the company table)
(The two tables had a dependency vie company_id (and the same name in both))
How can I do it?
Leo_a
create a transaction
insert into the dependent table
inserrt into the main table
commit
I'm not sure I understand the question. You want to select from one table and update the other with the data you selected from the first? Do you have any sample code you can post?

asp.net mvc custom modelbinder - how to perfom updates with assosciated entities

I am trying to understand how associated entities are updated when using custom modelbinders.
If you have a Product entity with a relationship to a Category entity and you are displaying a list of category choice for a product in a dropdown on a form.
The the user assigns a new category and that change needs to be persisted with the Product. How is the binding implemented to assign the updated category? The properties f the Product are easy enough, but how do you set the Product.Category = category?
Hope that is clear :-)
Sounds like your custom model binding is there, you're just trying to setup up your relationship between your Product and Category.
To do this you would do something like this:
product.CategoryReference.EntityKey =
new EntityKey("Context.Category", "ID", categoryID);
That will simply update the foreign key relationship in your entity.

Resources