1

Temat: Problem z relacją hasMany i conditions.

witam,

w modelu mam m.in. cos takiego:

    var $hasMany = array(
                    "ProductsDescription"=>array("className"=>"ProductsDescription",
                                                "foreignKey"=>"products_id",
                                                "conditions"=>null,
                                                "fields"=>null)
                    );

to mi generuje 2 zapytania:

SELECT `Product`.`id`, `Product`.`url`, `Product`.`symbol`, `Product`.`status`, `Product`.`images`, `Product`.`instrukcja` FROM `products` AS `Product` WHERE 1 = 1

oraz

SELECT `ProductsDescription`.`id`, `ProductsDescription`.`products_id`, `ProductsDescription`.`products_name`, `ProductsDescription`.`products_description`, `ProductsDescription`.`products_url`, `ProductsDescription`.`products_lang` FROM `products_descriptions` AS `ProductsDescription` WHERE `ProductsDescription`.`products_id` IN (1, 2)

co z kolei buduje ladna tablice

Array
(
    [0] => Array
        (
            [Product] => Array
                (
                    [id] => 1
                    [url]=> xxx
                    [symbol] => pp-01
                    [status] => 1
                    [images] => 
                    [instrukcja] => 
                )

            [ProductsDescription] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [products_id] => 1
                            [products_name] => Pxxx
                            [products_description] => 
                            [products_url] => pxxxt
                            [products_lang] => de
                        )

                    [1] => Array
                        (
                            [id] => 2
                            [products_id] => 1
                            [products_name] => xxx
                            [products_description] => 
                            [products_url] => xxx
                            [products_lang] => en
                        )

                    [2] => Array
                        (
                            [id] => 3
                            [products_id] => 1
                            [products_name] => xxx
                            [products_description] => 
                            [products_url] => xxx
                            [products_lang] => pl
                        )

                )

        )

    [1] => Array
        (
            [Product] => Array
                (
                    [id] => 2
                    [url]=> xxx
                    [symbol] => pp-01
                    [status] => 1
                    [images] => 
                    [instrukcja] => 
                )

            [ProductsDescription] => Array
                (
                )

        )

)

Problem w tym ze nie chce na raz wyciagac wszystkich jezykow, tylko aktualnie wybrany jezyk zapisany w cookie.

probowalem tak

    var $hasMany = array(
                    "ProductsDescription"=>array("className"=>"ProductsDescription",
                                                "foreignKey"=>"products_id",
                                                "conditions"=>array("ProductsDescription`.`products_lang"=>$ciasteczka),
                                                "fields"=>null)
                    );

ale wywala blad ze tam nie moze byc zmiennej.
dodatkowo czy tam gdzie jest generowana tablica to czy zamiast numerow moze byc pole z tabeli?
tzn zeby generowana tablica mogla wygladac tak

    [0] => Array
        (
            [Product] => Array
                (
                    [id] => 1
                    [url]=> xxx
                    [symbol] => pp-01
                    [status] => 1
                    [images] => 
                    [instrukcja] => 
                )

            [ProductsDescription] => Array
                (
                    [de] => Array
                        (
                            [id] => 1
                            [products_id] => 1
                            [products_name] => Pxxx
                            [products_description] => 
                            [products_url] => pxxxt
                            [products_lang] => de
                        )

                    [en] => Array
                        (
                            [id] => 2
                            [products_id] => 1
                            [products_name] => xxx
                            [products_description] => 
                            [products_url] => xxx
                            [products_lang] => en
                        )

                    [pl] => Array
                        (
                            [id] => 3
                            [products_id] => 1
                            [products_name] => xxx
                            [products_description] => 
                            [products_url] => xxx
                            [products_lang] => pl
                        )

                )

        )

    [1] => Array
        (
            [Product] => Array
                (
                    [id] => 2
                    [url]=> xxx
                    [symbol] => pp-01
                    [status] => 1
                    [images] => 
                    [instrukcja] => 
                )

            [ProductsDescription] => Array
                (
                )

        )

)

Z gory dzieki za zainteresowanie.

pozdr.

2

Odp: Problem z relacją hasMany i conditions.

IMHO łatwiej będzie napisać w modelu własną funkcje wyciągającą listę produktów w oparciu o parametr mówiący o żądanym języku.

3

Odp: Problem z relacją hasMany i conditions.

Mam jeszcze pytanko odnosnie relacji - zrobilem sobie jednak relacje hasOne i stanalem w miejscu bo nie wiem w jaki sposob dodac jeden wpis do products, a trzy wpisy do products_description.
Za kazdym razem dodawany jest osobny wpis do products oraz products_description.
czy relacja hasMany rozwiazala by to?

nie wiem czy wiesz co mam na mysli.

pozdr.

4

Odp: Problem z relacją hasMany i conditions.

Z tego co pisałeś wcześniej wnioskowałbym, że właśnie hasMany jest relacją najbardziej odpowiednią.