Can you use Mongo's populate function with Mongoid - mongoid

I have a list of Documents which each have a reference to another document in them. I want to sort the parent list based on a property in the referenced document. This seems like an obvious place to use Mongo's populate function but I can't seem to find anything regarding it.

Related

How put ContentDocument (Files) related list on external object? (Salesforce)

I have external objects and I desire to put the related list files on them, but it doesn't show this option, only custom objects that have relationship with they. How can I achieve that?

How can I use RelationshipFilter in 2sxc Visual Query with text field instead of entity field?

I'm trying to do the same as this example does under title "Attribute-On-Relationship to Query other Fields".
I'm editing Blog application visual query.
So I have RelationshipFilter, which takes entities of type Category via Default in point. And I want to filter them by field Name. Here I can get list of names either from params or from list of posts and their categories. That's not a problem as far as I understand.
So looks like Name has to be of entity type. I'm struggling right now with this filter, since I want to filter Category by field Name of simple text type. Which means that I have nothing to specify in Relationship Attribute. EntityTitle or just empty Relationship Attribute field don't work and cause Bad Request error. So is there a way to make it work?
P.S. ValueFilter is not an option, since it doesn't support returning nothing if there are no items, that satisfy condition and also it supports only filter by item's Attribute, that contains Value and no option that Value can contain any in Attribute with separator.
The RelationshipFilter is only meant for relationships (item with item) - and you seem to want to do a string-compare.
I'm not really sure what you should do because I don't have context, but if things get really special, best use LINQ instead. Check out the tutorials for LINQ here: https://2sxc.org/dnn-tutorials/en/razor/linq/home

CakePHP3 After removal of afterFind, where to check if query result empty?

Before i checked in the afterFind callback if the result of the find is empty.
Since the callback was removed in latest versions, where would be the place to check that from a behavior?
Im not realy sure if that is what i need. My use case is, i want to find out if a query has no result. Then i would create a default entry so it has 1 result.
https://book.cakephp.org/3.0/en/appendices/orm-migration.html#no-afterfind-event-or-virtual-fields
Once defined you can access your new property using $user->full_name. Using the Modifying Results with Map/Reduce features of the ORM allow you to build aggregated data from your results, which is another use case that the afterFind callback was often used for.
Call count() on the ResultSet object
https://api.cakephp.org/3.4/class-Cake.ORM.ResultSet.html#_count
No idea why you're not using that and want to do the count manually, but go on.
Using resultFormatter()
https://book.cakephp.org/3.0/en/orm/query-builder.html#adding-calculated-fields
You behavior will have to add the formatter in your beforeFind() to the query. You can add a custom find that adds it as well. Example code (taken from the docs):
$query->formatResults(function (\Cake\Collection\CollectionInterface $results) {
return $results->map(function ($row) {
$row['age'] = $row['birth_date']->diff(new \DateTime)->y;
return $row;
});
});
Count the results there.
Using map/reduce
https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#map-reduce
More often than not, find operations require post-processing the data that is found in the database. While entities’ getter methods can take care of most of the virtual property generation or special data formatting, sometimes you need to change the data structure in a more fundamental way.
You behavior will have to add the mapper/reducer in your beforeFind() to the query. You can add a custom find that adds it as well. Example code (taken from the docs):
$articlesByStatus = $articles->find()
->where(['author_id' => 1])
->mapReduce($mapper, $reducer);
Check the above link for a detailed explanation including examples of how to create a mapper and reducer.

I want to show the all the available custom object, Standard object based on custom selection

I have some requirement to list out all the custom objects and standard object detail with label name and api name using VF page. If I choose "Custom Object", Then page should list out all the custom object with the column of label name and api name. Thanks in advance.
I believe that your use case would be best suited to using the Schema.getGlobalDescribe method. With this method you can get a list of all the fields for a given object.
Schema.getGlobalDescribe.get('Contact') returns a Schema.describeObjectResult object that can be further probed to get the field names and labels. To get a Map of all the fields on the Contact object you could call:
Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap()
From that result you could iterate over the map to display all of the results. You would want to use an outputPanel with a nested repeat to produce the results.

Save error: Initial term of field expression must be a concrete SObject: MAP<String,AcctId__c>

I'm trying to get over a limitation in Salesforce where Lead objects can't have related lists that convert with the Lead over to Opportunity, Contact and Account. I have set up 4 objects of type Lookup Relationship, and created a dummy record in each.
I want to use Custom Settings to store the id of each of these dummy records, so that when the Lead converts, any custom objects can also convert to objects with Master/Detail relationships on the respective standard objects.
My trigger on Lead(after update) tries to create a Map of the Custom Settings:
Map cs = AcctId__c.getAll();
AcctId__c is the Custom Setting api name. Compile time is giving me the above message.
Now, I copied this code directly from the Salesforce documentation. What am I forgetting?
I believe that you must include the actual map definition <String,AcctId__c> after the word Map.
Check out this page.
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections_maps.htm

Resources