I have set up a Category-Product MANY_MANY relation,and I am trying to call a CActiveDataProvider for the Product model filtered by a specific Category to which it belongs.(to use it in a ListView).There is no foreign key connecting the two models,only the pivot table,so I don’t know what to use in CDbCriteria for the CActiveDataProvider argument.Thanks in advance !
Things are going quite well with this extension however I have run into a minor issue that perhaps one of you smarter people might be able to help with.
Example:
TABLES
Tourist: ID, NAME
Place: ID, NAME
rel_tourist_visited: Tourist_ID, Place_ID
rel_tourist_wishlist: Tourist_ID, Place_ID
Pretty simple, in the example a TOURIST may have visited many PLACES and a PLACE may have had many TOURISTS who have visited.
And, a TOURIST may wish to visit many PLACES and the PLACE may have many TOURISTS who wish to visit.
Problem:
If there is only one many_many between TOURIST and PLACE things are fine, it works exceptionally however as I have two I have run into issues.
When you choose to add/edit a record it will show a many_many list of checkboxes, but only for ONE of the relationships (I think the second in the list, alphabetically).
When you have a many_many relation and you want to update with saveWithRelated, if update have to delete a line in your relation table, it can cause some issues :
=> wait for an int but with 2 FK in the relation table it gaves me an array :
A solution is to replace in line 481 of GxActiveRecord.php :
// Delete one active record at a time.
foreach ($deleteMap as $value) {
$pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);
if (!$pivotModel->delete()) {
return false;
}
}
By :
// Delete one active record at a time.
foreach ($deleteMap as $value) {
if(is_array($value)){
$pivotModel = GxActiveRecord::model($pivotClassName)->findByAttributes($value);
}else{
$pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);
}
if (!$pivotModel->delete()) {
return false;
}
}
(Notice that in your controller you will have to set batch to false):
I can suggest that problem is about relation name generated in generateRelations() in ModelCode.php line 272 called
by "$this->relations = $this->generateRelations();" in GiixModelCode.php line 67 :
Inside generateRelations() is defined $relationName=$this->generateRelationName($table0, $table1, true); in ModelCode.php line 296
Well, creating “person” model with giix $relationName value for “person_workfor_organization” and “person_memberof_organization” tables was “organizations” so i’ve “lost” a relation caused by same array key assignment:
simply replace "$relationName=$tableName;" instead of "$relationName=$this->generateRelationName($table[X], $table[X], true);" in ModelCode.php line 29x [/b]
I understand that a pivot table should only be used for maintaining a m2m relationship between two tables and there should not be any extra fields other than the the FK columns that compose the PK.
But sometimes, we really want to add some extra fields in the pivot table. Since it contains extra data, this makes it not only serve the purpose of a pivot table but also becomes a model itself. Then we may probably prefer to add an extra id column to use it as the PK instead. Can or will giix generate proper codes to handle this case in the future?
Currently, giix generates checkboxes in the view for a m2m relationship but if there is an extra column, for example a varchar(100) column, in the pivot table, giix can simply generate a text field beside the checkbox.
By the way, I really like your extension, it’s very useful.
Hi! I can’t get this to work, which is awkward because it is only 3 steps and even I should be able to do that.
When I try use giix crud generator I get include(GxActiveRecord.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory
I’ve tried having the files in both
protected/extentions/giix-crud
protected/extentions/
When trying to create a Model I get : Class ‘GxActiveRecord’ does not exist or has syntax error.
To me it seems like I have some kind of path issue… But since I’ve tried all likely,unlikely places to put the files I have to ask here.
The settings in my main config file under import and gii is also correct.
When I read the readme under requirements it’s not 100% clear what you mean so just be sure:
On my localhost I use wamp with latest mysql and apache.
Hi, first of all, congrats for this excellent piece of code. I’m just starting with Yii and I found it very interesting.
Second, I found that giix does not create UNIQUE rule based on the UNIQUE flag of the field in the database. Is this an intended behaviour or is it a bug?
CREATE TABLE IF NOT EXISTS `yiitest`.`MasterAccount` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`rfc` VARCHAR(13) NOT NULL ,
`name` TEXT NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `rfc_UNIQUE` (`rfc` ASC) )
ENGINE = InnoDB
AUTO_INCREMENT = 2
DEFAULT CHARACTER SET = utf8
Looks like Gii is not taking into account the UNIQUE INDEX directive.
I see that the admin view created by Gii has the advanced search form hidden by default, and Giix doesn’t. Is it by design or is it a bug?
Eitherway, the fix is adding <div class="search-form" style="display:none"> on the search form when created.
[SOLVED] [s]Also, I want to ask you if you can include a search form also in the index view or if you can give me or guide me to a way to add the search form into a index view.
Guys, how do I use GUID’s there with that extension? Everytime I use a table with int’s, it works.
For instance, i make the model and then the CRUD with a table(i.e User) with an ID type int, it works, i can go to my website/user and it works. If i use GUID instead of int into the field ID, it doesn’t work.