Hello, I want to create a Yii Model (and likely CRUD actions) from a MySQL view instead of a table but I’m having problems with code generation trying to search for primary key.
Could any Yii guru try it and get it?
Doesn’t Yii framework support creating a model from a MySQL View?
From what I know and From the point of view of MySQL, a View generated from a table without JOINS or UNIONS beheave almost the same (with inserts, updates and deletes) as a table with the advantage of MySQL results cache. But even with JOINS or UNIONS we should be able to create models, after all it’s a Model.
Using this approach, one can quite easily generate the code necessary for Yii-based free-text search which also searches in related database tables. (would supply the link to a working example with source-code, but am not allowed to publish links on the forum…)
That is indeed a system-specific database access violation, and does not relate to the Yii code at least
Have your webhost equip your MySQL username with SHOW VIEW privileges for the database.
Has “Yii’s” stance on supporting CRUD operations on a MYSQL view changed since 2010?
I use views to easily have one query that returns numerous rows of properties that would otherwise require 10 or more joins. I just find it it tedious to generate a model/controller/view for each table.
First make your Create View. Please be alert that first column has id field that can be used primary key.
I make it by concat the id from some table that i use in create view.
CREATE VIEW view08_percabang_perpalet AS select
concat(jenisbarang_idaa01, cabangidbb04, areaidbb00) AS id,
sum(jumlahmasuk) as totalmasuk,
sum(jumlahmasuk)-sum(jumlahkeluar) as totalstock from
Group by cabangidbb04, areaidbb00, jenisbarang_idaa01
order by cabangidbb04, areaidbb00, jenisbarang_idaa01 ;
Make dummy table that has same structure with your Create View. Make sure the id field is primary key.
Fill your table with dummy data.
Generate Model with gii.
Delete that dummy table.
Rename your Create View same with that dummy table name.
Note : I use it,just to get use of the search tools in Manage Admin View.
It can not be use to add, delete or edit/update data.