We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

belongsTo in Models - $referencedField

Hi,

I have a problem with the belongsTo in Models and $referencedField param. It seems that if the $referencedField != 'id', the framework crashes with segmentation fault 11


$this->belongsTo('home_team', 'Core\Models\Soccer\SoccerTeams', 'code', array('alias' => 'hometeam', "foreignKey" => true));

CREATE TABLE `soccer_teams` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `short_name` varchar(5) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `code` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `code` (`code`),
  KEY `name` (`name`,`short_name`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

CREATE TABLE `soccer_match_info` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `match_data_id` int(10) unsigned NOT NULL,
  `match_day` smallint(5) unsigned DEFAULT NULL,
  `match_type` varchar(20) DEFAULT NULL,
  `match_winner` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `period` varchar(20) DEFAULT NULL,
  `round_number` smallint(5) unsigned DEFAULT NULL,
  `round_type` varchar(20) DEFAULT NULL,
  `venue_id` int(10) unsigned DEFAULT NULL,
  `match_date` datetime DEFAULT NULL,
  `match_date_tz` varchar(5) DEFAULT NULL,
  `venue` varchar(50) DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL,
  `home_team` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `away_team` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `competition_id` int(10) unsigned NOT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `match_data_id` (`match_data_id`),
  KEY `match_winner` (`match_winner`),
  KEY `home_team` (`home_team`),
  KEY `away_team` (`away_team`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

ALTER TABLE `soccer_match_info`
  ADD CONSTRAINT `soccer_match_info_ibfk_2` FOREIGN KEY (`away_team`) REFERENCES `soccer_teams` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `soccer_match_info_ibfk_1` FOREIGN KEY (`home_team`) REFERENCES `soccer_teams` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION;

Phalcon 2.0.0 / Apache 2.4 / PHP 5.5

  • Please don't ask "intelligent" questions like "why you don't use soccer_teams.id on home_team".


98.9k

Phalcon 2 is a copy of an old version of 1.3, can you try with 1.3.0?



51.2k

Thank you @Phalcon. It is working with 1.3.0. Anyway, if someone will try to build 1.3.0 and it will end up in an error "/usr/include/php5/ext/pcre/php_pcre.h:29:18: fatal error: pcre.h: No such file or directory" like i did, the solution is to install "libpcre3-dev" (apt-get install libpcre3-dev).

Thanks again.