HasMany relation

anne1979 21 Apr, 2016
Hi Bob,

I cannot get those joins working for my 4 tables =>

My 4 database tables are "j348_fahrzeug" (main model =Fahrzeug) and the other tables are linked to the main model via the field "lagernummer". Here is the debug output:

Array
(
    [0] => SELECT `Extension`.`id` AS `Extension.id`, `Extension`.`name` AS `Extension.name` FROM `j348_chronoengine_extensions` AS `Extension` WHERE `Extension`.`enabled` = '1' ORDER BY `Extension`.`ordering` ASC
    [1] => SELECT `Connection`.`id` AS `Connection.id`, `Connection`.`title` AS `Connection.title`, `Connection`.`params` AS `Connection.params`, `Connection`.`extras` AS `Connection.extras`, `Connection`.`published` AS `Connection.published` FROM `j348_chronoengine_connections` AS `Connection` WHERE `Connection`.`title` = 'sucheFahrzeuge' AND `Connection`.`published` = '1'
    [2] => SELECT COUNT(`Fahrzeug`.`id`) AS `Fahrzeug.count` FROM `j348_fahrzeug` AS `Fahrzeug` GROUP BY `Fahrzeug`.`lagernummer`
    [3] => SELECT `Fahrzeug`.`id` AS `Fahrzeug.id`, `Fahrzeug`.`seller` AS `Fahrzeug.seller`, `Fahrzeug`.`lagernummer` AS `Fahrzeug.lagernummer`, `Fahrzeug`.`make` AS `Fahrzeug.make`, `Fahrzeug`.`model` AS `Fahrzeug.model`, `Fahrzeug`.`model_description` AS `Fahrzeug.model_description`, `Fahrzeug`.`category` AS `Fahrzeug.category`, `Fahrzeug`.`description` AS `Fahrzeug.description`, `Fahrzeug`.`link` AS `Fahrzeug.link`, `Fahrzeug`.`emission` AS `Fahrzeug.emission`, `Fahrzeug`.`inner` AS `Fahrzeug.inner`, `Fahrzeug`.`outer` AS `Fahrzeug.outer`, `Fahrzeug`.`combined` AS `Fahrzeug.combined`, `Fahrzeug`.`unit` AS `Fahrzeug.unit`, `Fahrzeug`.`price` AS `Fahrzeug.price`, `Fahrzeug`.`currency` AS `Fahrzeug.currency`, `Fahrzeug`.`vatable` AS `Fahrzeug.vatable`, `Fahrzeug`.`vat_rate` AS `Fahrzeug.vat_rate`, `Fahrzeug`.`mileage` AS `Fahrzeug.mileage`, `Fahrzeug`.`fuel` AS `Fahrzeug.fuel`, `Fahrzeug`.`power` AS `Fahrzeug.power`, `Fahrzeug`.`condition` AS `Fahrzeug.condition` FROM `j348_fahrzeug` AS `Fahrzeug` GROUP BY `Fahrzeug`.`lagernummer` ORDER BY `Fahrzeug`.`model` ASC LIMIT 15
    [4] => SELECT `Spezifikation`.`id` AS `Spezifikation.id`, `Spezifikation`.`lagernummer` AS `Spezifikation.lagernummer`, `Spezifikation`.`key` AS `Spezifikation.key`, `Spezifikation`.`bezeichnung` AS `Spezifikation.bezeichnung` FROM `j348_fahrzeugspezifikation` AS `Spezifikation` WHERE `Spezifikation`.`lagernummer` IN ('4', '1', '3', '2') GROUP BY `Spezifikation`.`lagernummer`
    [5] => SELECT `Ansicht`.`id` AS `Ansicht.id`, `Ansicht`.`lagernummer` AS `Ansicht.lagernummer`, `Ansicht`.`key` AS `Ansicht.key`, `Ansicht`.`link` AS `Ansicht.link` FROM `j348_fahrzeugimage` AS `Ansicht` WHERE `Ansicht`.`lagernummer` IN ('4', '1', '3', '2') GROUP BY `Ansicht`.`lagernummer`
    [6] => SELECT `Feature`.`id` AS `Feature.id`, `Feature`.`lagernummer` AS `Feature.lagernummer`, `Feature`.`key` AS `Feature.key`, `Feature`.`bezeichnung` AS `Feature.bezeichnung` FROM `j348_fahrzeugfeature` AS `Feature` WHERE `Feature`.`lagernummer` IN ('4', '1', '3', '2')
)


I also add a screenshot of my model (1 related table as example).

For me, it looks as if the foreign key field is ignored and "id" is used instead. The numbers 1-4 are row ids, a "lagernummer" (INT 11) is something like '16025'... Where am I going wrong?

Help really appreciated,
Anne
anne1979 21 Apr, 2016
Here is the model screenshot.
This topic is locked and no more replies can be posted.