nvlad / yii2support

Yii2 Support for PhpStorm / IntelliJ IDEA
https://plugins.jetbrains.com/idea/plugin/9388-yii2-support
Other
295 stars 54 forks source link

About table prefix support and there may be has a BUG #142

Closed zhang988925 closed 6 years ago

zhang988925 commented 7 years ago
  1. More often, we do not write tableName, So, for the user experience
public static String getTableByActiveRecordClass(PhpClass phpClass) {
    Method method = phpClass.findMethodByName("tableName");
    if (method != null) {
    "……"
    }
    String className = phpClass.getName();
    // Change here
    return AddTablePrefix(StringUtils.CamelToId(className), true, phpClass.getProject());
}
  1. com/nvlad/yii2support/common/DatabaseUtils.java In the 268 line

    public static ArrayList<String> getColumnsByTable(String table, Project project) {
    // This My be a BUG can cause duplicate
    String prefixedTable = AddTablePrefix(table, true, project);
    
    DbPsiFacade facade = DbPsiFacade.getInstance(project);
    List<DbDataSource> dataSources = facade.getDataSources();
    
    ArrayList<String> list = new ArrayList<>();
    if(table == null)
        return list;
    table = ClassUtils.removeQuotes(prefixedTable);
    for (DbDataSource source : dataSources) {
        for (Object item : source.getModel().traverser().children(source.getModel().getCurrentRootNamespace())) {
    
        if (item instanceof DbTable && ((DbTable) item).getName().equals(prefixedTable)) {
            TableInfo tableInfo = new TableInfo((DbTable) item);
            for (DasColumn column : tableInfo.getColumns()) {
            list.add(ClassUtils.removeQuotes(column.getName()));
            }
        }
        }
    }
    return list;
    }