Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
senasi opened this issue Aug 12, 2016 · 1 comment

Comments

@senasi
Copy link

senasi commented Aug 12, 2016

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...

@senasi
Copy link
Author

senasi commented Aug 12, 2016

PR included: #141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant