⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation with where parameter



noplan
  • profile picture
  • Member

Posted 17 March 2019 - 14:44 PM

Hi,

 

I can't get my controller function running and at least I reached a point where I'm not sure if I completely misunderstood the set_relation function.

I'm using grocery crud 1.6.2 with codeigniter 3.1.9.

My MySQL database looks like:

-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Erstellungszeit: 15. Mrz 2019 um 00:52
-- Server-Version: 5.7.25-1
-- PHP-Version: 7.1.27

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


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

--
-- Datenbank: `gc_db1`
--

-- --------------------------------------------------------
--
-- Tabellenstruktur fuer Tabelle `kurs_termin`
--

CREATE TABLE `kurs_termin` (
  `kurs_termin_id` mediumint(8) UNSIGNED NOT NULL,
  `kurs_id` smallint(5) NOT NULL,
  `termin_id` smallint(5) NOT NULL,
  `kurs_termin_status_id` smallint(5) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Daten für Tabelle `kurs_termin`
--

INSERT INTO `kurs_termin` (`kurs_termin_id`, `kurs_id`, `termin_id`, `kurs_termin_status_id`) VALUES
(1, 37, 1, 1),
(2, 37, 4, 1),
(3, 38, 1, 1),
(4, 38, 4, 1);


-- --------------------------------------------------------
--
-- Tabellenstruktur fuer Tabelle `termin`
--

CREATE TABLE `termin` (
  `termin_id` smallint(5) UNSIGNED NOT NULL,
  `termin_datum` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Daten für Tabelle `termin`
--

INSERT INTO `termin` (`termin_id`, `termin_datum`) VALUES
(1, '2018-09-24'),
(2, '2018-09-26'),
(3, '2018-09-27'),
(4, '2018-10-01');

/*!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 */;

my controller function looks like this:

public function kurs_management()
{
   $crud = new grocery_CRUD();
   $crud->set_table('kurs_termin');
   $crud->columns('kurs_id', 'termin_id');
   $crud->display_as('termin_id','Datum');
   $crud->set_relation('termin_id', 'termin', 'termin_datum', array('termin.termin_datum >=' => '2018-10-01'), NULL);
			
   $output = $crud->render();
   $this->_example_output($output);
}

My expectation is that I get two rows displayed like:

37   2018-10-01

38   2018-10-01

 

but I get all four entries of table 'kurs_termin' displayed.

 

Does anyone has an idea where my fault is?

 

Cheers

 

noplan