jasonhinkle / phreeze

Phreeze Framework for PHP
http://phreeze.com/
GNU Lesser General Public License v2.1
377 stars 166 forks source link

Relation not working in one case only #212

Open raheelkhan opened 9 years ago

raheelkhan commented 9 years ago

image

image

In the above image keyword id is a foreign key which is referencing to keywords table. I don't understand why it is showing a text box here. Where as if you see the vendor id and tariff id fields that has the same relations and are being shown in dropdown.

I need your advice what should cause this problem. I have double check the field types in database also.

Need your help urgently

Thanks Raheel

jasonhinkle commented 9 years ago

Hmm that is odd, would you be able to share a create table script that could reproduce the problem? I can't really see why it isn't working either, but somehow it's not being recognized as a relationship.

raheelkhan commented 9 years ago
-- --------------------------------------------------------

--
-- Table structure for table `keyword_tarrif_vendor`
--

CREATE TABLE IF NOT EXISTS `keyword_tarrif_vendor` (
  `keyword_tarrif_vendor_id` int(11) NOT NULL AUTO_INCREMENT,
  `keyword_id` int(11) NOT NULL,
  `vendor_id` int(11) NOT NULL,
  `tariff_id` int(11) NOT NULL,
  `date_applicable` datetime NOT NULL,
  PRIMARY KEY (`keyword_tarrif_vendor_id`),
  UNIQUE KEY `keyword_id_2` (`keyword_id`),
  KEY `keyword_id` (`keyword_id`,`vendor_id`),
  KEY `keyword_id_3` (`keyword_id`),
  KEY `tarrif_id` (`tariff_id`),
  KEY `vendor_id` (`vendor_id`),
  KEY `keyword_id_4` (`keyword_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `keyword_tarrif_vendor`
--
ALTER TABLE `keyword_tarrif_vendor`
  ADD CONSTRAINT `keyword_tarrif_vendor_ibfk_3` FOREIGN KEY (`tariff_id`) REFERENCES `tariffs` (`tariff_id`),
  ADD CONSTRAINT `keyword_tarrif_vendor_ibfk_1` FOREIGN KEY (`keyword_id`) REFERENCES `keywords` (`keyword_id`),
  ADD CONSTRAINT `keyword_tarrif_vendor_ibfk_2` FOREIGN KEY (`vendor_id`) REFERENCES `vendors` (`vendor_id`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
-- --------------------------------------------------------

--
-- Table structure for table `keywords`
--

CREATE TABLE IF NOT EXISTS `keywords` (
  `keyword_id` int(11) NOT NULL AUTO_INCREMENT,
  `keyword` varchar(25) NOT NULL,
  `shortcode_id` int(11) NOT NULL,
  PRIMARY KEY (`keyword_id`),
  KEY `shortcode_id` (`shortcode_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `keywords`
--
ALTER TABLE `keywords`
  ADD CONSTRAINT `keywords_ibfk_1` FOREIGN KEY (`shortcode_id`) REFERENCES `shortcodes` (`shortcode_id`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Here are both the tables thank you for your attention.

Esysc commented 9 years ago

Hello, I've never investigated about it, but every time

-----Original Message----- From: "Raheel Khan" notifications@github.com Sent: ‎10/‎07/‎2015 06:47 PM To: "jasonhinkle/phreeze" phreeze@noreply.github.com Subject: [phreeze] Relation not working in one case only (#212)

In the above image keyword id is a foreign key which is referencing to keywords table. I don't understand why it is showing a text box here. Where as if you see the vendor id and tariff id fields that has the same relations and are being shown in dropdown. I need your advice what should cause this problem. I have double check the field types in database also. Need your help urgently Thanks Raheel — Reply to this email directly or view it on GitHub.

jasonhinkle commented 9 years ago

From what I can see, the issue has to do with the compound keys being used:

PRIMARY KEY (`keyword_tarrif_vendor_id`),
...
KEY `keyword_id` (`keyword_id`,`vendor_id`),

This actually isn't a problem for Phreeze itself, but it is a problem for the builder app - it doesn't currently know how to deal with compound keys. What you can do is temporarily remove the compound keys, generate your code, then put the constraints back in. I have a feeling this is why the builder is skipping that column.

Also a lot of your keys are named the same as the columns, which I don't think is a problem but it might help with troubleshooting to give the keys unique names.

odgatelmand commented 8 years ago

I suppose, it's linked to this problem.

Maybe there is a problem with the layer of the popup.

In my DB i have two fields with table relations.

I tried on Chrome and Safari.

On the popup. The first field is working great. But when I go down the popup to select the second field, . When I click the selector of the second field, nothing happen. To find the different possible selections I have to up the popup. You can see on the screen that the selections of different states are on the phone field.

Do you know how to fix it ?

explanation