T
T
Test Test2015-09-17 16:27:10
Yii
Test Test, 2015-09-17 16:27:10

How to properly bind data in Yii1?

Hello! I'm scratching my head about table relationships in Yii. Let's say we have three tables and data in these tables:
Lookup - (id, type, code, title) - currency data is stored in the table, just their code and title

1, price_currency, 10, rur
2, price_currency, 20, usd
2, price_currency, 30, eur

StoreItem - (id, name, price, price_currency) - table of items with prices and currency (where price is the price and price_currency is the recorded currency code)
1, предмет №1, 1000, 10
2, предмет №2, 2000, 20
3, предмет №3, 1000, 30

CrossCourse (sell, buy, course) - table of cross-currency rates. Everything is clear here.
rur, rur, 1
usd, rur, 50
eur, rur, 60

-------------------------------
Now about the models and their relationships:
In theory, in the StoreItem model, we should make a relationship with Lookup , in order to get the name of the currency (code), and, accordingly, somehow get a connection with CrossCourse so that we get the currency pair rate field (course).
What I tried to do:
I tried to set a MANY_MANY relationship to the Lookup table, but I couldn't do it, because it didn't form the LEFT JOIN query correctly. He tried to connect t.id = t.code , but he needed t.price_currency = t.code
PS In the future, the price will be formed in the field (price * course) AS price_course
PSS Fields code, price_currency, course - not unique, not having a key

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentine, 2015-09-22
@Tpona

item 4 : www.yiiframework.com/doc/guide/1.1/ru/database.arr
www.yiiframework.com/doc/guide/1.1/ru/database.arr...
And in general, why do you want to use as foreign key to link to Lookup - code, and d CrossCourse stuffed title from Lookup?
Some of this is redundant.
Or I misunderstood something

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question