geting maximu value in a table column - yii2

I am trying to get maximum value of id column
$taskid = (new Query())->select('MAX(id)')->from('member');
echo $taskid;
unfortunate I got the below text
O:12:"yii\db\Query":20:{s:6:"select";a:1:{i:0;s:7:"MAX(id)";}s:12:"selectOption";N;s:8:"distinct";N;s:4:"from";a:1:{i:0;s:21:"member";}s:7:"groupBy";N;s:4:"join";N;s:6:"having";N;s:5:"union";N;s:6:"params";a:0:{}s:18:"queryCacheDuration";N;s:20:"queryCacheDependency";N;s:27:"yii\base\Component_events";a:0:{}s:35:"yii\base\Component_eventWildcards";a:0:{}s:30:"yii\base\Component_behaviors";N;s:5:"where";N;s:5:"limit";N;s:6:"offset";N;s:7:"orderBy";N;s:7:"indexBy";N;s:16:"emulateExecution";b:0;}
please help me out

Maximum id value of Member model:
use app\models\Member;
// ...
echo Member::find()->max('id');

Related

display filled field as empty field mysql view

How can I display as view a filled field as empty field in mysql?
It's about the field klanten.KlantEmail
thanks in advance
SELECT
klanten.KlantId,
klanten.KlantRelid,
klanten.KlantU4relid,
klanten.KlantZoeknaam,
klanten.KlantNaam,
klanten.KlantStraat,
klanten.KlantHuisnummer,
klanten.KlantAdres,
klanten.KlantPostcode,
klanten.KlantPlaats,
klanten.KlantPostbus,
klanten.KlantEmail
FROM
klanten
No you would do this, assuming you want to output the column but have it as a empty string regardless or what is really in the column
SELECT
klanten.KlantId,
klanten.KlantRelid,
klanten.KlantU4relid,
klanten.KlantZoeknaam,
klanten.KlantNaam,
klanten.KlantStraat,
klanten.KlantHuisnummer,
klanten.KlantAdres,
klanten.KlantPostcode,
klanten.KlantPlaats,
klanten.KlantPostbus,
"" as klanten.KlantEmail
FROM
klanten

Updating a Set Field Type with using Laravel

I have a form with a series of checkboxes. The name of the checkboxes is name="groups[]".
<input type="checkbox" name="groups[]" value="value-1">
<input type="checkbox" name="groups[]" value="value-2">
<input type="checkbox" name="groups[]" value="value-3">
<input type="checkbox" name="groups[]" value="value-4">
I want to save the values submitted to a column named groups in a MySQL database. My Laravel update code is as follows:
$record->groups = $attributes['groups'];
$record->save();
I have also tried:
$record->groups = implode(',', $attributes['groups']);
$record->save();
Just in case it helps, the field details in the migration file is:
$table->set('groups', ['value-1','value-2','value-3','value-4'])->nullable();
The error receiving is:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'groups' at row 1 (SQL: update `table` set `groups` = ["value-1","value-2"] where `id` = 1)
Is my update code incorrect for Laravel and Set columns?
I tried Googling a lot, but because the term set is used in regular update queries, I'm not getting helpful results.
Edit: Added Table Structure
Column
Type
id
bigint(20)
groups
set('value-1','value2','value-3','value-4')
Edit: Results of my attributes:
array: 1 [▼
"groups" => array:2 [▼
0 => "value-1"
1 => "value-2"
]
]
'''
It ends up that the correct method to update a set type column is to implode the array into a comma separated string. I thought I tried this earlier, but it's working now, not actually sure why it wasn't before and is now. Here is the working update:
$proposal->groups = implode(',', $attributes['groups']);
$proposal->save();

Error when trying to split a column using powerquery in Azure Data Factory -UserQuery : Expression.Error: An error occurred invoking 'Table.AddColumn'

I get the following error when trying to split a column by space delimiter on PowerQuery in Data Factory :
UserQuery : Expression.Error: An error occurred invoking 'Table.AddColumn': We can't get the expression for the specified value.
What is causing this and how would I go about resolving it?
Many thanks
This is the error
The PowerQuery itself is :
let
Source = dedupedetipscsv,
#"Split Column by Delimiter" = Table.SplitColumn(Source, "Candidate", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"Candidate.1", "Candidate.2"}),
#"Split Column by Delimiter1" = Table.SplitColumn(Table.TransformColumnTypes(#"Split Column by Delimiter", {{"ApprovedDate", type text}}, "en-GB"), "ApprovedDate", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"ApprovedDate.1", "ApprovedDate.2"})
in
#"Split Column by Delimiter1"
Note: Power Query will split the column into as many columns as needed. The name of the new columns will contain the same name as the
original column. A suffix that includes a dot and a number that
represents the split sections of the original column will be appended
to the name of the new columns.
In the Table.AddColumn step might refer to variable which is a List. You need to refer to #"Renamed Columns" which is the last step that results in a table.
Split columns by delimiter into columns | Here
Make sure : An alternate for split by length and by position is listed below | M script workarounds
Table.AddColumn(Source, "First characters", each Text.Start([Email], 7), type text)
Table.AddColumn(#"Inserted first characters", "Text range", each Text.Middle([Email], 4, 9), type text)

Validaing Multiple, Specific Form Fields with errors()

I am building a multi-step form input (a "wizard") where the user input parts of an entity over multiple form input views. At each step, I want to validate only the input data (not the entire entity).
My question is how to use error() with an array of field names.
The model has 12 fields with validation rules. I want to validate 3 of those in one controller action.
So, in this controller action, I get three inputs
$thedata = $this->request->data;
This results in:
['number' => '102','color' => 'blue','size' => 'large']
I then make an array of field names:
$thearray = array_keys($thedata);
This results in:
[
(int) 0 => 'number',
(int) 1 => 'color',
(int) 2 => 'size']
Now I would like to check these three fields for errors.
$errors = $this->Items->newEntity($this->request->data)->errors($thearray);
This results in checking ALL 12 fields with validation defined, not just the three in the array, and it fails validation (it picks up all the errors in the entity).
If I define only ONE field to check it works:
$errors = $this->Items->newEntity($this->request->data)->errors('number');
This correctly validates only the field 'number' and produces the desired result.
However, passing an array of fields instead of a string with a single field name validates ALL fields requiring validation.
Also, I tried hard-coding an array as a parameter of errors():
$errors = $this->Items->newEntity($this->request->data)->errors(['number','color']);
That also checks all 12 fields in the table definition, not just these two.
So the question is, how do you prepare the array and pass it to the errors() method if you want to check only two or three specific fields?
Thanks in advance for any advice!
D
Thanks in
According to the docs errors can take a $field argument, but not an array. If you want to validate multiple fields without validating all of them, you could loop over $thearray.
$item = $this->Items->newEntity($this->request->data);
foreach ($thearray as $error) {
$errors[] = $item->errors($error);
}

Rails where clause match integer with the array

I have an issue in finding the correct records from the database. This is my query:
#interested_individual = Profile.where('category_id = ?', #event.interests).all
Where category_id is the column in the profiles table what holds the integer value and #event.interests returns an array that is ["1", "2", "3"]
What I want here is to fetch all the profiles where its category_id is present in the #event.interests array.
Please let me know the solution. Thanks in advance
You don't really need to manually write the binding with ? and all.
Try this:
#interested_individual = Profile.where(category_id: #event.interests).all
Active Record will then turn that into category_id IN (?) for you if you pass in an array.
This query will translate to category_id IN [interest_ids...]
Profile.where(category_id: #event.interests).all
You were close. Use IN.
#interested_individual = Profile.where('category_id IN (?)', #event.interests).all
But, I would suggest find you here, if you are only wanted to get collection of all Profile records :
#interested_individual = Profile.find(#event.interests)