I want to generate a drop down select list with the form helper of CakePHP,
I'am trying to pass an array in the $this->Form->input() method which is obtained in the folowing
way $colors = $this->Color->find('all',...);$this->set('colors', $colors);.
thanks in advance.
UPDATE:
What I'm trying to do in CakePHP is this (in SQL code):
SELECT id, color
FROM colors Color WHERE id NOT IN (SELECT color_id FROM product_size_colors psc WHERE psc.product_id=16);
How can I replicate the above query in cakephp?
find('list') is what you need to look into...
by default thats going to get the id,name fields..
$colors = $this->Color->find('list');
$this->set('colors', $colors);
Related
I want to filter the array which is structed using json_extract. Specifically, I am using below script to pull data:
select
ARRAY(
SELECT STRUCT(JSON_EXTRACT_SCALAR(loads, '$.barcode') as barcode, JSON_EXTRACT_SCALAR(loads, '$.eventDate') as eventDate)
FROM UNNEST(JSON_EXTRACT_ARRAY(payload, "$.JSONDocument.load")) loads
) shipment,
from table
and I want to filter JSON_EXTRACT_SCALAR(loads, '$.eventDate').
Any answers is appreciated
So I have a table listing all kind of url types (for example: Facebook, Instagram, Twitter, etc.)
I want to achieve result similar to from this one:
select
url
,(case
when url like '%facebook%' then 'Facebook'
when url like '%instagram%' then 'Instagram'
....
end) as type
However the problem is the list goes on with around 30-40 items, and I don't want to list them all manually.
Is there any way to achieve this?
I'm thinking about using loop but can't get it right.
Thank you.
Not exactly an answer to your question, but maybe as an alternative you can use REGEXP_EXTRACT:
WITH test_table AS (
SELECT "https://www.facebook.com/qwe" AS url UNION ALL
SELECT "http://abc.instagram.com/zxc"
)
SELECT
url,
REGEXP_EXTRACT(url, r"^https?:\/\/([^\/?]+)") AS type
FROM test_table
EDIT:
Similar to Michel's brilliant suggestion you can create additional table with a list of domains and their search strings. But make sure that single url won't fall under several conditions otherwise such url will be duplicated in the output.
WITH test_table AS (
SELECT "https://www.facebook.com/qwe" AS url UNION ALL
SELECT "http://abc.instagram.com/zxc"
),
social_networks AS (
SELECT '%facebook%' as search_string, 'Facebook' AS type UNION ALL
SELECT '%instagram%', 'Instagram'
)
SELECT
url, social_networks.type
FROM test_table JOIN social_networks
ON test_table.url LIKE social_networks.search_string
i have a view object that contains the following attributes
studentId
courseId
enrollDate
notes
and I have added 2 attributes, which are
studentName
courseName
and I want to select their values from another table(student,course) based on an SQL query.
i have tried to make a default value :SQL
and wrote the following query
select Course.courseName from Course where StudentCourse.CourseId = Course.id
but it didn't work.
You can get their values from an SQL query. This may help. Or this. Or this.
Hello I currently have 2 tables like this:
Parcel which has idParcel,quantityParcel,idProduct
and
Product which has idProduct, nameProduct
When I try to execute Aggr( sum(quantityParcel),[idProduct] ) it works just fine making the sum of quantityParcel by idProduct but when I try to run Aggr( sum(quantityParcel),[nameProduct] ) it just returns the sum of all quantityParcel values without grouping anything, is there any way I can group by nameProduct referencing it from the Product table? The reason I want to do this is because I want to show the actual product name in my dimension instead of just the idProduct number, thanks :)
If you use nameProduct as Dimension why don't just use: sum(quantityParcel)
another option is to use NODISTINCT : Aggr(NODISTINCT sum(quantityParcel),[nameProduct] )
Using OrientDB 2.* with OrientSQL.
I have a simple graph with Class Users that has a number of properties (username, country, pets, etc). Each user also has outgoing friends edge. I want to select only the username and country from all users who are friends with a specific user.
My query so far:
SELECT EXPAND( BOTH('friends') ) FROM users WHERE #rid = #12:0
returns the full user objects for those who are friends of #12:0
I want only to return the username and country of those friends.
Am I missing something simple? Much appreciated!
You can:
select expand(both('friends').include('username', 'country'))
from #12:0
Note that you should:
select from #12:0
instead of:
select from Users where #rid = #12:0
A sub-query would work. I don't think there is any other way to do this.
Try this :
select
username, country
from (select
expand( both('friends') )
from
#12:0)