Welcome, Guest
Username: Password: Remember me

TOPIC: Join replacing the values

Join replacing the values 11 Nov 2012 16:07 #5289

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Admin has a question :


I would like to begin the multilang support and I cannot see where is the multilingual support in Joomla Native.

Joomla do not support what Joomfish was supporting. The main difference is that the languages clones are not clones, but copies and the ID of the referent item is lost.

It means that we do not simply have to translate, but to recreate the whole structure of menus, categories and all items you can have in DB.

So, to my opinion Cook cannot use this native system.


The way I am choosing is simple :

A translatable table is containing all original entries AND partial copies of what have to be translated. But the difference is the overridings rows will contain the ID of their related original ID (rel key)
'language' key will be instancied normally.

So, my problem is in SQL.

I want to select my full row of the first table, and when a translation is found on the joined table, then the values of the main table are OVERRIDED by the values presents in the second table.

How can I do ?

I tried to look after LEFT, RIGHT, INNER, OUTER, .. JOINS, but it is not what I am searching for.
My request is only to replace the fields (not phisically, but only for the result of the query) when a row has been catched in the other table :

a. = main table (contents to translate)
_translation_. = related table (row to override the first one)

When a.id = _translation_.rel

Any clues ?
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Join replacing the values 11 Nov 2012 16:13 #5290

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I must precise that the main table and the joined table are the SAME.

It is a recursive link that keep trace to the original element of this same table.

For advanced users :
In this concept, if there is only 1 field translatable, the best will be to create a 1:1 link to place the others non translatable fields. It is only a question of optimization in this case.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Join replacing the values 11 Nov 2012 16:34 #5291

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Excellent to see COOK thinking about this!

Can I throw a complete spanner in the works? What about tying into the Google Translate API and having all cook components leveraging the power of automatic translation?

Would MySQLs union statement be what you're looking for maybe?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Join replacing the values 11 Nov 2012 17:02 #5294

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin what about using a CASE statement so if values exist in translation table, you get those values instead, otherwise get the values from the 'original' table:
SELECT 
(CASE WHEN t1.field = {something} THEN table1.field ELSE t2.field END) 
FROM table1 t1, table2 t2
???
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 11 Nov 2012 17:08 by JoomGuy. Reason: FORGOT TO ADD t1.field = something
The administrator has disabled public write access.

Re: Join replacing the values 11 Nov 2012 17:08 #5295

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
To mark edited previous..

*********ADD*********
Link 1: mysql-tips.blogspot.co.uk/2005/04/mysql-...ct-case-example.html
Link 2: www.w3resource.com/mysql/control-flow-fu...ns/case-operator.php
**********END********
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 11 Nov 2012 17:17 by JoomGuy. Reason: ADDED LINKS
The administrator has disabled public write access.

Re: Join replacing the values 11 Nov 2012 17:21 #5296

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I take that it works fantastic.

Many thanks.

I only need to see how it works to plan the future.
The versioning will be implemented such same way.

And also still the same way : A Time Machine. Why not ?
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Join replacing the values 11 Nov 2012 17:36 #5297

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin,

I guess you'll want to check to see IF EXISTS in the translation table in the CASE statement to get the requested language fields then return the row obj if true or return the original if false, right?

It looks as if this could get pretty complex so I hope it suits your needs!

Good luck,

Gez

P.S. Is there a release date on the cards for the implementation of nested sets yet?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 11 Nov 2012 17:39 by JoomGuy.
The administrator has disabled public write access.

Re: Join replacing the values 15 Nov 2012 10:47 #5374

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Yep, it will becomes a bit complex, but I found a way to do it very nice and simple, whatever language string I want to translate at any level of FK.
For the moment iti will not be implemeted because of a lot to do in the builder, and because of few things in the sandbox (implementing native languages, and more...)
It is going on, as well as the 2.0 finishing.

Nothing new about Nested.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Join replacing the values 21 Nov 2012 07:10 #5528

  • mark d
  • mark d's Avatar
What you need is to move the orderDateTime criteria to the join clause instead of where clause like:

SELECT prod.product, COALESCE(COUNT(pord.oid),0) AS orderCount,
COALESCE(SUM(pord.orderPrice),0) AS orderSum
FROM product_manufacturer AS manu
JOIN product_list AS prod ON prod.ref_manufacturer_id = manu.mid
LEFT JOIN product_orders AS pord
ON pord.ref_product_id = prod.pid
AND DATE(pord.orderDateTime) BETWEEN :orders_start AND :orders_end
WHERE manu.mid = :manu_id
GROUP BY prod.product;

The reason it does not work within the WHERE clause is because of the NULL values returned from the outer join.
The administrator has disabled public write access.

Re: Join replacing the values 21 Nov 2012 08:19 #5535

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
mark d wrote:
What you need is to move the orderDateTime criteria to the join clause instead of where clause like:

SELECT prod.product, COALESCE(COUNT(pord.oid),0) AS orderCount,
COALESCE(SUM(pord.orderPrice),0) AS orderSum
FROM product_manufacturer AS manu
JOIN product_list AS prod ON prod.ref_manufacturer_id = manu.mid
LEFT JOIN product_orders AS pord
ON pord.ref_product_id = prod.pid
AND DATE(pord.orderDateTime) BETWEEN :orders_start AND :orders_end
WHERE manu.mid = :manu_id
GROUP BY prod.product;

The reason it does not work within the WHERE clause is because of the NULL values returned from the outer join.
UNRELATED: Please refrain from posting this unrelated stuff!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
Time to create page: 0.105 seconds

Get Started