标签: jointable

在cakephp中连接两个表时,只选择了一个表的数据

我使用了这段代码,但只选择了一个表的数据.

我需要从两个表中选择所有字段:

$options['joins'] = array(
                array('table' => 'tbl_users',
                    'alias' => 'Users',
                    'type' => 'INNER',
                    'foreignKey' => 'assigned_by',
                    'fields' => 'Users.user',
                    'conditions' => array(
                        'TravancoAdmin.assigned_by = Users.id'
                    )
                )
            );
            $options['conditions'] = array( 'TravancoAdmin.id' => $task_id);
$result = $this->find('all', $options);
        return $result ? $result : 1;
Run Code Online (Sandbox Code Playgroud)

如何从两个表中获取所有字段?

如果我的代码有任何错误?

cakephp jointable

1
推荐指数
1
解决办法
1995
查看次数

使用magento命令连接自定义表

我一直在尝试使用magento的命令加入两个自定义表.搜索后,我遇到了这个通用代码块

$collection = Mage::getModel('module/model_name')->getCollection();
$collection->getSelect()->join( array('table_alias'=>$this->getTable('module/table_name')), 
'main_table.foreign_id = table_alias.primary_key',
 array('table_alias.*'), 
'schema_name_if_different');
Run Code Online (Sandbox Code Playgroud)

在此之后为模板我试图加入我的表连接在一起,但只返回错误,如incorrect table nametable doesn't exist或其他一些错误.

只是为了清理事情,有人可以根据我的理解纠正我

$collection = Mage::getModel('module/model_name')->getCollection();

获取模型的实例.在该模型中是保存所需数据的表(对于此示例,我将调用表p)

$collection->getSelect()

从表p中选择数据

->join()

需要三个参数才能将两个表连接在一起

PARAM1

array('table_alias'=>$this->getTable('module/table_name'))

'您为表提供的名称'=>'要添加到集合中的表(已在模型文件夹中设置)'

PARAM2

'main_table.foreign_id = table_alias.primary_key'

这一点我没有得到(虽然看起来很直接)

我的主表(p)没有外来ID(它有它的主键 - 它也是它的外来ID)?

必须等于你在param1中给出的字母名称

参数3

'main_table.foreign_id = table_alias.primary_key'

从所有名称中获取所有内容

我的理解在哪里出错了?

magento jointable

1
推荐指数
1
解决办法
7730
查看次数

BookshelfJs无法在创建时引入嵌套关系

比方说,我们有一个连接表vehicle_inspections,另一个连接表inspection_actions,以及为基本表actions,vehicles, andinspections`.

让我们说我希望以下数据库条目:

 vehicles
 ----------------------------
 id        make
 ----------------------------
 1         Toyota



actions
-------------------------------
id        description
-------------------------------
2         Check Tire Pressue

inspections
-------------------------------
id        location        date
-------------------------------
3         New York      tomorrow

vehicle_inspections
--------------------------------
vehicle_id      inspection_id   
--------------------------------
1                3

inspection_actions
--------------------------------
inspection_id     action_id
--------------------------------
3                 2
Run Code Online (Sandbox Code Playgroud)

和以下书架课程

inspection_actions.js

(function () {
    'use strict';
     var Repository = require('../repository');
     module.exports = Repository.Model.extend({
       tableName: 'inspection_actions',
     });  
})();
Run Code Online (Sandbox Code Playgroud)

vehicle_inspections.js

(function () {
    'use strict';
     var Repository = require('../repository');

     module.exports …
Run Code Online (Sandbox Code Playgroud)

postgresql jointable express bookshelf.js knex.js

1
推荐指数
1
解决办法
1157
查看次数

Rails HBTM join_table覆盖table_name

我正在运行Rails 2.3.2并且正在执行:

class StandardWidget < ActiveRecord::Base
  has_and_belongs_to_many :parts, :join_table => "widgets_parts", :association_foreign_key => "widget_custom_id"
end

class Part < ActiveRecord::Base
  has_and_belongs_to_many :widgets, :join_table => "widgets_parts", :association_foreign_key => "part_custom_id"
end

p = StandardWidget.find(5)
p.widgets
Run Code Online (Sandbox Code Playgroud)

并得到错误

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'widgets_parts.standard_widget_id' in 'where clause': SELECT * FROM `widgets`  INNER JOIN `widgets_parts` ON `parts`.part_custom_id = `widgets_parts`.part_custom_id WHERE (`widgets_parts`.standard_widget_id = 5 )
Run Code Online (Sandbox Code Playgroud)

我怎样才能使这个工作?

关于HBTMRails文档说:

警告:如果要覆盖任一类的表名,则必须在任何has_and_belongs_to_many声明下声明table_name方法才能工作.

这是什么意思?

ruby-on-rails associations has-and-belongs-to-many tablename jointable

0
推荐指数
1
解决办法
1751
查看次数

Oracle:连接两个表来复制2个表的行

我有2个如下表:

Table 1
---------
   1  
   2  
   3   


 Table 2
--------    
   A   
   B   
   C
Run Code Online (Sandbox Code Playgroud)

我如何加入以获得如下输出:

Output
---------
1 A  
1 B  
1 C  
2 A  
2 B  
2 C  
3 A  
3 B  
3 C
Run Code Online (Sandbox Code Playgroud)

sql oracle join jointable

0
推荐指数
1
解决办法
118
查看次数

根据帖子类型加入3个不同的表格

我有3张桌子

帖子(包含每个帖子类型)

ID | type | PostID | timestamp
1  | 1    | 1      | 1378561301
2  | 2    | 1      | 1378561302
3  | 1    | 2      | 1378561303
4  | 2    | 2      | 1378561304
Run Code Online (Sandbox Code Playgroud)

posts_messages

ID | message
1  | CAT
2  | RAT
Run Code Online (Sandbox Code Playgroud)

posts_photos

ID | photo      | caption
1  | ant.jpg    | Ant
2  | orange.jpg | Orange
Run Code Online (Sandbox Code Playgroud)

而且我想得到这样的结果

结果:

ID | Type | PostID     | timestamp  | message   | photo      | caption
1  | …
Run Code Online (Sandbox Code Playgroud)

php mysql sql jointable

0
推荐指数
1
解决办法
56
查看次数