Im as u can see in my history kinda new into kohana, but learning quick.. I am struggling on a weird problem that worked before in Kohana 3.3
I want to create a join query between two databases. i created the Model_Veiligen en Model_Veilingvoorkeur models, and put this as ORM call:
This is the RIGHT JOIN QUERY:
SELECT `vastprijs`, `veilingen`.`id` AS `id`, `veilingen`.`gid` AS `gid`, `veilingen`.`provincie` AS `provincie`, `veilingen`.`created` AS `created`, `veilingen`.`termtime` AS `termtime`, `veilingen`.`postcode` AS `postcode`, `veilingen`.`lat` AS `lat`, `veilingen`.`lng` AS `lng`, `veilingen`.`titel` AS `titel`, `veilingen`.`beschrijving` AS `beschrijving`, `veilingen`.`images` AS `images`, `veilingen`.`ip` AS `ip`, `veilingen`.`unique` AS `unique` FROM `veilingen` AS `veilingen` RIGHT JOIN `veilingvoorkeur` ON (`veilingen`.`id` = `vid`) ORDER BY `veilingen`.`created` DESC LIMIT 10
DIT IS DE LEFT:
SELECT `vastprijs`, `veilingen`.`id` AS `id`, `veilingen`.`gid` AS `gid`, `veilingen`.`provincie` AS `provincie`, `veilingen`.`created` AS `created`, `veilingen`.`termtime` AS `termtime`, `veilingen`.`postcode` AS `postcode`, `veilingen`.`lat` AS `lat`, `veilingen`.`lng` AS `lng`, `veilingen`.`titel` AS `titel`, `veilingen`.`beschrijving` AS `beschrijving`, `veilingen`.`images` AS `images`, `veilingen`.`ip` AS `ip`, `veilingen`.`unique` AS `unique` FROM `veilingen` AS `veilingen` LEFT JOIN `veilingvoorkeur` ON (`veilingen`.`id` = `vid`) ORDER BY `veilingen`.`created` DESC LIMIT 10
RIGHT JOIN output:
[_object:protected] => Array ( [id] => [gid] => [provincie] => [created] => [termtime] => [postcode] => [lat] => [lng] => [titel] => [beschrijving] => [images] => [ip] => [unique] => [vastprijs] => 56 )
LEFT JOIN OUTPUT:
[_object:protected] => Array ( [id] => 121 [gid] => 10 [provincie] => 9 [created] => 1385534362 [termtime] => 1386743962 [postcode] => 8031CJ [lat] => 52.528510 [lng] => 6.081043 [titel] => gdfgd [beschrijving] => fgfdgdfgfdsfsfd [images] => [{"file_name":"5a5a7a7ef44.png","file_size":238687,"file_type":"image\/png","file_link":"uploads\/\/5a5a7a7ef44.png"}] [ip] => 94.215.33.178 [unique] => [vastprijs] => )
My code for the Left or right join is as follows:
$veiling = ORM::factory('veilingen')
->select('vastprijs')
->join('veilingvoorkeur', 'RIGHT')
->on('veilingen.id', '=', 'vid')
->order_by('veilingen.created', DESC)
->limit(10)
->find_all();
The problem im hanging into is that i don't understand the has_many and belongs_to, the example above worked before, but not anymore.
The problem that occurs if i change RIGHT in LEFT, it will output all data from the veilingen table. But it ignores the data of the vastprijs field. But if i print the foreach element, i can see that the vastprijs has been selected. Except for data.
If i use RIGHT, instead of left. above story occurs but then otherwise. vastprijs isn't empty and veilingen fields are empty. but shown.
My main question is, how can i relate those 2 tables together with maybe has_many, but veilingen only has_one veilingvoorkeur. The key is veilingen.id = veilingvoorkeur.vid
has_many/belongs_to(1:n) relationship? - keroveilingvoorkeuralways have a related item inveilingen(or canvidbe empty)? - kero