$model_reg_b = BusinessNatureMappingForm::model()->findbyPk($model_reg);
foreach ($model_reg_b->BusinessNatureMappingForm as $keyi1 => $model_reg_bb) {
$model_ownerm = OwnershipSpecificDetailsForm::model()->findByAttributes(array("bnsd_bnmid" => $model_reg_bb->bnm_regid));
}
I think that you use a model as the parameter of findbyPk() instead of a primary key attribute (e.g. $model_reg->id).
Change this:
$model_reg_b = BusinessNatureMappingForm::model()->findbyPk($model_reg);
To this:
$model_reg_b = BusinessNatureMappingForm::model()->findbyPk($model_reg->primary_key_column);
Related
I am new to elasticsearch so I will need some help. Unfortunately, I didnt found the answer in other topics here on SO.
I have some .net core application which I inherited and now there is a need to implement some changes.
I already have a method of getting data from elasticsearch, but after getting them, I am not sure how to change it and use it in application.
To be precise, I need to parse first and last name and to remove special characters, specific serbian latin letters like "šđžčć" etc... I already have a method for this parsing written but not sure how to call it...
So, my question is can I and how can I do this?
What I have now is the following:
var result = await _elasticClient.SearchAsync<CachedUserEntity>(
s =>
s.Index(_aliasName)
.Query(q => andQuery));
CachedUserEntity, among others, contains property about FirstName and LastName.
Inside results.Documents, I am getting the data about FirstName and LastName from elasticsearch, but I am not sure how to access it in order to update it via aformentioned NameParser ...
Sorry if the question is too easy, not to say stupid :)
I wont use updateByQuery here, for some reasons. I would scroll on documents (i use matchAll on my exemple, you obviously need to replace it with your query), or, if you dont know how to identify documents to update, only update usefull documents in UpdateManyWithIndex/UpdateManyPartial function.
For performance, we have to update severals documents at once, so we use bulk/updateMany function.
You can use both solution, the classic update, or the second (partial update) with an object containing the targeteds fields.
On server sides, both solutions will have the same cost / performance.
var searchResponse = Client.Search<CachedUserEntity>(s => s
.Query(q => q
MatchAll()
)
.Scroll("10s")
);
while (searchResponse.Documents.Any())
{
List<CachedUserEntity> NewSearchResponse = RemoveChar(searchResponse);
UpdateManyWithIndex<CachedUserEntity>(NewSearchResponse, _aliasName);
searchResponse = Client.Scroll<Project>("2h", searchResponse.ScrollId);
}
public void UpdateManyWithIndex<C>(List<C> obj, string index) where C : class {
var bulkResponse = Client.Bulk(b => b
.Index(index).Refresh(Elasticsearch.Net.Refresh.WaitFor) // explicitly provide index name
.UpdateMany<C>(obj, (bu, d) => bu.Doc(d)));
}
Or, using partial update object
Note: in this case Indix is already set on my client (add .index if needed)
var searchResponse = Client.Search<CachedUserEntity>(s => s
.Query(q => q
MatchAll()
)
.Scroll("2h")
);
while (searchResponse.Documents.Any())
{
List<object> listPocoPartialObj = GetPocoPartialObjList(searchResponse);
UpdateManyPartial(listPocoPartialObj);
searchResponse = Client.Scroll<Project>("2h", searchResponse.ScrollId);
}
private List<object> GetPocoPartialObjList(List<CachedUserEntity> cachedList) {
List<object> listPoco = new List<object>();
//note if you dont have cachedList.Id, take a look at result.source, comments if needed
foreach (var eltCached in cachedList) {
listPoco.Add( new object() { Id = cachedList.Id, FirstName = YOURFIELDWITHOUTSPECIALCHAR, LastName = YOURSECONDFIELDWITHOUTSPECIALCHAR});
}
return listPoco;
}
public bool UpdateManyPartial(List<object> partialObj)
{
var bulkResponse = Client.Bulk(b => b
.Refresh(Elasticsearch.Net.Refresh.WaitFor)
.UpdateMany(partialObj, (bu, d) => bu.Doc(d))
);
if (!bulkResponse.IsValid)
{
GetErrorMsgs(bulkResponse);
}
return (bulkResponse?.IsValid == true);
}
For reference I'm using the Serenity application template.
I have the following code
var query = new SqlQuery();
query.From("TenantData")
.Select("ItemData")
.Select("ItemType")
.Where(new Criteria("TenantID") == userDefinition.TenantId);
using (var connection = sqlConnections.NewByKey("Default"))
{
var data = connection.Query(query);
}
The data returned looks like {{DapperRow, ItemData = '2342342wef', ItemType = 'test'}}
What I'm struggling with is how to convert this into a dictionary (ItemData being the key, ItemType being the value).
I've tried a select but it doesn't seem to be supported so I'm at a bit of a loss.
The following should work.
var data = connection.Query(query);
var d = data.ToDictionary(row => (string)row.itemdata, row => (string)row.itemtype);
Make sure you add the using System.Linq; at the top. ToDictionary() is an extension method.
I have a method in my api Controller which have the following signature
[HttpGet]
[Route("api/Controller/GetResult")]
public ApiResult<List<IDocument>> GetResult(DateTime date, Guid id, List<Guid> Ids)
I need to call it using PostMan but I don't know how to send the last argument which is a list of Guid in the parameter list, any help?
you can replace all params with JObject as following :
pass JSON:
{"date":"2019-02-17", "id":"00000000-0000-0000-0000-000000000001", "Ids":["00000000-0000-0000-0000-111111111111", "00000000-0000-0000-0000-222222222222"]}
ACTION:
public ApiResult<List<IDocument>> GetResult(JObject json)
{
DateTime date = json.FirstOrDefault(x => x.Name == "date"))?.Value.ToString(); // simple parameter
//----> output: "2019-02-17"
Guid id = new Guid(json.FirstOrDefault(x => x.Name == "id"))?.Value.ToString()); // simple parameter
//----> output: "00000000-0000-0000-0000-000000000001"
List<JToken> Ids = json.FirstOrDefault(x => x.Name = "Ids")?.Value.ToList(); // list
//----> output: ["00000000-0000-0000-0000-111111111111", "00000000-0000-0000-0000-222222222222"]
//you should specify the type of "JToken" values as this:
List<Guid> IdsList = new List<Guid>();
foreach (var Id in Ids)
{
IdsList.Add(new Guid(Id.Value<string>()));
}
}
You can use postman in-build Dynamic Variable $guid .
This generates a v4 style guid at runtime.
Try this GET request using Postman:
https://httpbin.org/anything?IDs=["{{$guid}}","{{$guid}}","{{$guid}}"]
Using QueryOver I am creating a query like this
BulkActionItem bulkActionItemAlias1 = null;
BulkActionItem bulkActionItemAlias2 = null;
var query = GetSession().QueryOver<Student>(() => studentAlias)
.JoinAlias(() => studentAlias.BulkNotifications, () => bulkActionItemAlias1, NHibernate.SqlCommand.JoinType.LeftOuterJoin);
if (query.UnderlyingCriteria.GetCriteriaByAlias("bulkActionItemAlias2") == null
query = query.JoinAlias(() => studentAlias.BulkNotifications, () => bulkActionItemAlias2, NHibernate.SqlCommand.JoinType.LeftOuterJoin);
This will crash because I have the same join twice with different aliases. Is it possible to check if a join already exists on a query, even with a different alias?
I haven't found a built-in way to accomplish this. Typically I use an out parameter with extension methods to keep track of what tables are part of the query. For example:
bool joinedOnBulkNotifications;
BulkNotification notificationAlias = null;
Expression<Func<object>> aliasExpr = () => notificationAlias;
var query = GetSession().QueryOver<Student>(() => studentAlias)
.FilterByBulkNotificationStatus(
someCondition, aliasExpr, out joinedOnBulkNotifications);
public static class QueryExtensions
{
public static IQueryOver<Student, Student> FilterByBulkNotificationStatus(
this IQueryOver<Student, Student> query,
bool someCondition,
Expression<Func<object>> aliasExpr,
out bool joinedOnBulkNotifications)
{
joinedOnBulkNotifications = false;
if (someCondition)
{
joinedOnBulkNotifications = true;
query.JoinAlias(s => s.BulkNotifications, aliasExpr);
}
return query;
}
}
The issue is that you might need to reuse the alias you created later. You might be tempted to pass in a BulkNotification and use that, but this only works if the parameter name matches the name of the variable you pass to the extension method. NHibernate uses the name of the variable to create an alias name, so if these two do not match, you'll get an error. Because of this, you need to wrap the alias in an Expression and use that instead.
This isn't a very clean option, so I hope someone has a better solution.
I have 5 text form
$number1 = new Text('number-1');
$number2 = new Text('number-2');
$number3 = new Text('number-3');
....
with the relative filters
foreach(...)
$input = new Input($elementName);
$validator = new ValidatorChain();
$validator->addByName('Int')
->addByName('Between', array(
'min'=>0,
'max'=>$this->maxAllowedTicket,
'inclusive'=>true));
$filter = new FilterChain();
$filter->attachByName('Int');
$input->setValidatorChain($validator);
$input->setFilterChain($filter);
I would that only one of this 3 forms can contain a value different from 0.
There are then two possible errors.
TOO MANY NUMBERS
$data['number1'] = 5;
$data['number2'] = 5;
$data['number3'] = 0;
$data['number4'] = 5;
$data['number5'] = 0;
NO NUMBER
$data['number1'] = 0;
$data['number2'] = 0;
$data['number3'] = 0;
$data['number4'] = 0;
$data['number5'] = 0;
How can I validate this multiple fields at the same time ?
You need to write your own Validator class to do so. The isValid() method of your new validation class also receives the $context which includes the values of the whole form. This way you can validate the value of each field depending on the other fields.
namespace My\Validator;
use Zend\Validator\AbstractValidator;
class CustomValidator extends AbstractValidator
{
public function isValid($value, $context = null)
{
// put your logic here and call
// $this->error(); if required
}
}
Craft your own solution using the Callback validator.
Examples are here: http://packages.zendframework.com/docs/latest/manual/en/modules/zend.validator.set.html#callback