Skip to content

joinWhere is not working with aliases and table chains not beginning with ":" #142

@senasi

Description

@senasi

Recently added feature, specifying additional conditions for table joins (joinWhere method) is not working correctly with table aliases and chains not beginning with ":".

SqlBuilder is not including parameters, so SqlDriver is giving exception:

SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

Simple test:

CREATE TABLE `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `article` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `category_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_category` (`category_id`),
  CONSTRAINT `FK_article_category` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tag` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_tag_category` (`category_id`),
  CONSTRAINT `FK_tag_category` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `category` VALUES ('1', 'Test category');
INSERT INTO `article` VALUES ('1', 'Test', '1');
INSERT INTO `tag` VALUES ('1', '1', 'tag');
$database->table('article')
    ->select('article.*')
    ->joinWhere('category:tag', 'category:tag.name', 'tag')
    ->fetch();
$database->table('category')
    ->select('category.*')
    ->alias(':tag', 'a')
    ->joinWhere('a', 'a.name', 'auto')
    ->fetch();

These both are giving Exception...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions