I'm unable to run the FindBy magic function property in Extbase MVC
$title=array(0 =>'Books Day');
$each_event=$this->eventRepository->findByTitle($title);
$each_event is returning an object of type TYPO3\CMS\Extbase\Persistence\Generic\QueryResult .
How do I make this work?
I also tried passing in a string to findByTitle and findByOne. Both don;t work! :(
I'm using TYPO3 6.1 and extension builder.
The last part of those magic functions always needs to be a field in the database. So "title" must be in your model. You might have a field "one" for your object, but I guess you meant findOneByTitle?
The object type QueryResult is correct. You can turn it into an array for debugging purpose for example:
$foo = $query->execute()->toArray();
By the way: check wether your eventRepository is null or not and you could try this to see if it works at all:
$result = $this->myRepository->findAll();
Try
$each_event=$this->eventRepository->findByTitle($title)->toArray();
Reference to the QueryResult.
As said in the documentation, it returns a QueryResultInterface|array.
As a consequence you have to loop over the result like this:
foreach($each_event as $single_event) {
$single_event->getProperty();
}
If you are sure that it returns only one single value you could also access it by the index 0:
$each_event[0]->getProperty();
Related
I am having lookup wherein salesforce query is there. I am using elements (item()) in subsequent activities. Till now i had item().name or item().email but now i have item().NVMStatsSF__Related_Lead__r.FirstName which has (dot) in the field name.
How should i parse it through body tag so that it reads it correctly?
So I have the following data in item()
{
"NVMStatsSF__Related_Lead__c": "00QE000egrtgrAK",
"NVMStatsSF__Agent__r.Name": "ABC",
"NVMStatsSF__Related_Lead__r.Email": "geggegg#gmail.com",
"NVMStatsSF__Related_Lead__r.FirstName": "ABC",
"NVMStatsSF__Related_Lead__r.OwnerId": "0025434535IIAW"
}
now when i use item().NVMStatsSF__Agent__r.Name it will not parse because of (dot) after NVMStatsSF__Agent__r. And it is giving me the following error.
'item().NVMStatsSF__Related_Lead__r.Email' cannot be evaluated because property 'NVMStatsSF__Related_Lead__r' doesn't exist, available properties are 'NVMStatsSF__Related_Lead__c, NVMStatsSF__Agent__r.Name, NVMStatsSF__Related_Lead__r.Email, NVMStatsSF__Related_Lead__r.FirstName, NVMStatsSF__Related_Lead__r.OwnerId'.",
"failureType": "UserError",
"target": "WebActivityToAddPerson"
this is because ADF uses '.' for object reading.
Could you find a way to rename the field name which contains '.'?
Seems like you need a built-in function to get the value of an object according to the key. Like getValue(item(), 'key.nestkey'). But unfortunately, seems there isn't such a function. You may need handle your key first.
Finally, it worked. I was being silly.
Instead of taking the value from the child table with the help of (dot) operator I just used subquery. Silly see.
And it worked.
I would like to look up and return an object referenced by a different column to that of id.
As far as I know there isn't another method similar to Task::findOrFail($id) but that can reference another field. For example:
Task::findOrFail('column_name' = 'column_data');
I'm currently using
Task::where('tid' , '=', $tid)->first();
Is this possible?
Maybe you can use the firstOrFail() function of Laravel.
Task::where('column_name', '=' ,'column_data')->firstOrFail();
I need to check whether the Property contains one of the or all following strings
"C-I", "C-II", "C-III", "C-IV", "C-V"
if not it Errormessage must be
"Invalid Property. Must be blank or C-I, C-II, C-III, C-IV, or C-V.",
i don know which "DataAnnotation Attribute" to use and How? if possible please provide sample.
You could use the Regular Expression data annotation. However, I would recommend implementing IValidatableObject on your data class. You can then write your custom logic within the Validate method. This way, if/when those valid options change, you would just be modifying a collection, rather then trying to figure out a new valid regex statement.
It can be done using anyone of the follwing Attributes
**
1.EnumDataTypeAttribute
2.CustomValidationAttribute
3. Creating New Custom Attribute.
**
I've written a class validator as a service and passed the doctrine entity manager to this validator. At this point everything works fine.
But now I need the unchanged object of $entry which is been updated in the form - or at least the previous values. I've tried some approaches, but did not succeed:
public function isValid($entry, Constraint $constraint)
{
$oldEntry = $this->em->getRepository('SomeBundle:Entry')->findOneBy(array('id' => $entry->getId()));
Doctrine fetches the same (changed) object as expected. But trying to refresh the object will reset both versions of the object:
$newEntry = clone $entry;
$this->em->detach($newEntry);
$this->em->refresh($entry);
$hoursOfOldEntry = $entry->calculateHours();
$this->em->merge($newEntry);
Another option could be to save the values of the object as array, refresh the object and reassign the saved values again after working on the original values. But this does not seem to be the best way, especially if the are many relations. I don't wont to touch the object within a validator, I just need the previous values!
Another approach could be using Doctrine\ORM\UnitOfWork#recomputeSingleEntityChangeSet(Doctrine\ORM\ClassMetadata $meta, $entity). But I don't think it's a good idea to use internal doctrine methods in a validator!
So how do I get the original object or the change set in a class validator?
This won't get you the original entity, but should get you a key/value array of the original fields:
$uow = $em->getUnitOfWork();
$originalData = $uow->getOriginalEntityData($entry);
http://www.doctrine-project.org/api/orm/2.0/source-class-Doctrine.ORM.UnitOfWork.html#2210
I have created a doctype in umbraco which has one of the following property:
Property - Case study link
Datatype - Content picker
I need to fetch the URL of this document in a Razor macro and assign it to a hyperlink.
Currently am doing it in this way but it's giving me an error:
#foreach (var item in #Model.OurWork){
Read case study
}
And here is the error I get on viewing the page:
Error loading Razor Script OurWorkGrid.cshtml The best overloaded
method match for 'umbraco.library.NiceUrl(int)' has some invalid
arguments
I have tried outputting the node id without using the niceURL() function and it works fine (outputs 1088).
Read case study
results in this:
Read case study
But as soon as I put back NiceURL() function, it chokes again.
I really don't know what am I doing wrong here!
Instead of using the umbraco library method, try loading the node with the ID first, and then using the Url property to get the nice URL.
#foreach (var item in #Model.OurWork){
var caseStudyNode = #Model.NodeById(item.caseStudyLink);
Read case study
}
Also, add some form of a check to make sure the value is set, in case it's not a mandatory property on the doc type. Here's one example:
if (#item.HasProperty("caseStudyLink") && !string.IsNullOrEmpty(#item.caseStudyLink))
{
...
}
Try something like:
#foreach (var item in #Model.OurWork){
Read case study
}
You may want to check first whether item.caseStudyLink contains a value because this will throw an error otherwise.