2sxc Hybrid How to access and update a multi-entity field to add new one - dotnetnuke

Using Dnn v9.10.2 and 2sxc v13.2
I have a content type with an Entity-type field that holds multiple items, and I need to add a new one to the list from code. I believe that I need to call App.Data.Update(EntityId, Dictionary<string, object>) where the dictionary key is the field name and the value should be a list of EntityGuids, and the list should include all of the existing entities as well. Is that correct? If so how do I access the existing list of entities?
When trying to access the multi-entity field it shows its type as DynamicObject and not a list. I tried several ways of accessing the contents of the field from code including wrapping it in AsList() to use in a foreach loop, but the foreach never runs through an iteration. Is there a different type I need to cast it to inside of the AsList?

Related

RavenDB - How to backpopulate "old" documents after adding new property to POCO?

I'm just starting to learn about NoSQL/Document storage this morning. I am used to EntityFramework/SQLServer.
My questions is the following: If I have a bunch of "documents" stored and somewhere down the line I add a property to my class that is needed by my app, how do I back-populate the already existing records?
If you change the model after the fact then you have a few options.
If you have a default value for the additional field and can wait until the next time that entity is saved for the database then you can simply add the new property and set the value to the defaultv value in the constructor.
You can use a IDocumentConversionListener (http://ayende.com/blog/66563/ravendb-migrations-rolling-updates)
You can also use https://github.com/khalidabuhakmeh/RavenMigrations which I have never used but it seems like it would do what you want.

Field Collections of Entity References in Views

I have been tinkering with this problem and trying to research for a few hours. I am still getting familiar with the entity API for Drupal 7, and have been trying to work with PHP but to no avail--I think I am missing something VERY obvious as a result of my tired brain over-thinking things.
I have two Content Types, CT1 and CT2. CT1 has a field that can hold multiple Field Collection values. In this Field Collection (field_coll_ct2) one of the fields (field_ct2_ref) is an Entity Reference to a node of content type CT2.
Now, when I am looking at a single node of type CT1, I want a block View that will show me all of the CT2 nodes referenced in that CT1 node's field_coll_ct2 field collection field.
My primary approach, which has worked on non-field collection fields of the same kind of relation, is to add a contextual filter to the view on Content:NID. From there, since it is a block and URL parameter passing is out of the question (there are so many of these kinds of relations between 7-8 different content types, at different tuples per node, it is absolutely not feasible to use the URL for parameter-passing) I have it set to 'Provide default value' of type 'PHP' and 'allow multiple values' and here is where it gets hairy.
I need to get all of the field_ct2_ref entity references in the currently-viewed node's field_coll_ct2 field collections. I've tried using:
$wrapper = entity_metadata_wrapper($entity_type, $entity);
return $wrapper->field_coll_ct2->field_ct2_ref->value();
or
$node=menu_get_object();
foreach ($node->field_coll_ct2['und'] as $record)
{
$values[]= $record['value'];
}
foreach($values as $val){
$tgts[]=$val['every'][index]['possible'];
}
return $tgts[omg];
and probably close to a hundred variations of the above trying to get it to return something that vaguely resembled an entity reference to a CT2 type node.
I can't seem to dig deeply enough into the entity/field references to get to the field_ct2_ref['und'][0]['target_id'] that has worked for all non-field collection fields with this kind of relationship. Or I get AJAX errors telling me 'Unknown data property field_coll_ct2' or console errors saying that every index I try to throw at these array objects (to even just get ONE of the values) is wrong.
Is there an easier way of doing this? Am I missing something simple and obvious--either in the way I'm implementing my View or the PHP itself?
For what it's worth, I've been able to narrow down the view results without any contextual filter by selecting a relation to 'Referencing Entity: field_ct2_ref' but it shows ALL CT2 nodes referenced by ANY CT1 type node rather than the specific CT1 type node I'm looking at.
Thank you!

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

Drupal 7, Get values of an Entity Reference in a Field Collection

I've got a field collection, which contains
A copy field
A user field, via entity reference
Now when I try to access the copy field by storing the collection in $collection, via
$collection->field_my_collection_copy->value();
I get what im looking for, but trying similar on the entity referenced field
$collection->field_my_collection_user->value();
It breaks. By looking into the variables for $collection->field_my_collection_user I should have 'uid' available on it, but $collection->field_my_collection_user->uid gives me nothing and $collection->field_my_collection_user->uid->value(); gives me Unable to get the data property uid as the parent data structure is not set
It could be because Field Collection doesn't inherently know what node type their parent is associated with.

DRY unique objects in Django

I want to ensure an object is unique, and to throw an error when a user tries to save it (e.g. via the admin) if not? By unique, I mean that some of the object's attributes might hold the same values as those of other objects, but they can't ALL be identical to another object's values.
If I'm not mistaken, I can do this like so:
class Animal(models.Model):
common_name = models.CharField(max_length=150)
latin_name = models.CharField(max_length=150)
class Meta:
unique_together = ("common_name", "latin_name")
But then each time I refactor the model (e.g. to add a new field, or to change the name of an existing field), I also have to edit the list of fields in the parenthesis assigned to unique_together. With a simple model, that's OK, but with a substantial one, it becomes a real hassle during refactoring.
How can I avoid having to repeat typing out the list of field names in the unique_together parenthesis? Is there some way to pass the list of the model's fields to a variable and to assign that variable to unique_together instead?
Refactoring models is a rather expensive thing to do:
You will need to change all code using your models since field names correspond to object properties
You will have to change your database manually since Django cannot do this for you (at least the version I used the last time when I worked with Django couldn't)
Therefore I think updating the list of unique field names in the model meta class is the least issue you should worry about.
EDIT: If you really want to do this and all of your fields must be "unique together", then the guy at freenode is right and you'll have to write a custom metaclass. This is quite complicated and errorprone, plus it might render your code incompatible to future releases of Django.
Django's ORM "magic" is controlled by the metaclass ModelBase (django.db.models.base.ModelBase) of the generic base class Model. This class is responsible to take your class definition with all fields and Meta information and construct the class you will be using in your code later.
Here is a recipe on how you could achieve your goal:
Subclass ModelBase to use your own metaclass.
Override the method __new__(cls, name, bases, dict)
Inspect dict to gather the Meta member (dict["Meta"]) as well as all field members
Set meta.unique_together based on the names of the fields you gathered.
Call the super implementation (ModelBase.__new__)
Use the custom metaclass for all your unique models using the magic member __metaclass__ = MyMetaclass (or derive an abstract base class extending Model and overriding the metaclass)

Resources