magical record importing data and relationships - ios

I'm trying to auto import data using MagicalRecord. I've read all the answers that I've found, but do not understand is it possible or not. This is how my data model looks like:
There are two steps in my app. First I'm getting organization data, and I import it using
[organization MR_importValuesForKeysWithObject:response];
This works fine, later I'm getting participants, and import them using
[participant MR_importFromArray:response];
this also works ok, only I want to also get the participant relationships added. Json that I'm getting for participants looks like this:
(
{
CoverImage = "<null>";
Id = 4377;
LogoImage = "<null>";
Name = "Participant name";
ParentOrganizationId = 2;
Phone = "123 123-1234";
}
)
ParentOrganizationId is the organizationID to which organization this participant belongs.
So the question is, when importing participants is it possible to set this relationship to already saved organizations? Maybe I need to setup relatedByAttribute or mappedKeyName in my attributes user info and that's it?
Any guidance is appreciated, thanks in advance!

Well, after 3 days of searching I've finally found it. It is possible!
This is where i found the solution to this problem.
All I had to do was
In Organization model participants relationship add mappedKeyName "Participants"
In Participant model parentOrganization relationship add mappedKeyName "ParentOrganizationId" and relatedByAttribute "organizationID".
And everything works fine using this.

Related

How to make a join with two tables with django-tables2

Can anyone provide a clear example of how to show a table using django-tables2 that selects and presents data from two(or more) related models?
I've found lots of posts about that, most of them quite old, and none really a working example.
These are my models:
class Person(models.Model):
name = models.CharField(verbose_name="Name",max_length=50)
fname = models.CharField(verbose_name="F.Name",max_length=50)
class Speech(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
said = models.CharField(verbose_name="Said",max_length=50)
I simply want to show a table with columns "Name, F.Name, Said". Which is the best way? And with multiple tables?
Thanks in advance.
Well, nobody answered my question. After digging and trying I found a way to show fields from related models in one table. The thing is the table definition into tables.py should be like this:
class SpeechTable(tables.Table):
name = tables.Column(accessor='person.name')
fname = tables.Column(accessor='person.fname')
said = tables.Column()
class Meta:
attrs = {"class": "paleblue"}
Not sure if this is the best way, but it is simple and works fine.

Lua nested tables, table.insert function

i started learning lua and now i'm trying to deal with nested tables.
Basically i want to create a kind of local "database" using json interaction with lua (i found out that was the best thing to store my values)...
what i supposed to do is to scan all members inside a chatgroup (i'm using an unofficial telegram api) and store some values inside a table. I was able to retrieve all datas needed, so here's the structure declared in main function:
local dbs = load_data("./data/database.json")
dbs[tostring(msg.to.id)] = {
gr_name = {},
timestamp = "",
user = { --user changes into user ids
us_name = {},
us_nickname = {},
us_role = ""
},
}
where msg.to.id contains a valid number. This is what i tried to do:
dbs[tostring(id)]['users'][tostring(v.peer_id)]['us_nickname'] = v.username
this one works but this one:
dbs[tostring(id)]['users'][tostring(v.peer_id)] = table.insert(us_name,v.print_name)
(id is a correct number and matches with first field, same as all values passed like v.peer_id and v.print_name so those are not the problem)
gives error "table expected"... i'm pretty sure i have totally no idea of how to insert an element in such a table like mine.
Can anyone of you be so kind to help me? I hope to be clear enough explaining my issue.
Thanks in advance to everyone :)
To add new user name to an existing user you probably want to insert it into the sub-table like this:
table.insert(dbs[tostring(id)]['users'][tostring(v.peer_id)].us_name, v.print_name)

How to retrieve beans using two relations on redbean

I would like to retrieve some data using one-to-many and many-to-many relations
I've created bean called floor, shop, category and related them as:
floor 1:N shop
floor N:M category
shop N:M category
Now i want to retrive all shops given category and floor ids
Here is my code
$floor = R::load('floor',$f_id);
$category = R::load('category',$cat_id);
$shops= $floor->via('category')->withCondition('id = ?',[$category ->id])->ownShopList;
var_dump($shops);
But $data is empty array. I'm shure i've related beans correctly. What am I doing wrong please help!
Maybe there is another way to retrieve them i'll appreciate any solution. Thanks!
$category = R::load('category',$cat_id);
$shops= $category->withCondition('floor_id = ?',[$f_id])
->sharedShopList;
I've figured it out finally after couple of hours was very easy and simple. so here is the solution
$category = R::load('category',$cat_id);
$shops= $category->withCondition('floor_id = ?',[$f_id])->sharedShopList;
var_dump($shops);

Dynamics CRM Merge Two Contacts with C# code, modified example from SDK

I've been trying to get the Merge example in Dynamics CRM 2011 SDK to work.
http://msdn.microsoft.com/en-us/library/hh547408.aspx
I've modified it a bit. I've created two Contacts instead of Accounts (although some variable names in the code might suggest otherwise. For example _account1Id is in fact a GUID for contact1.)
The first Contact record has name, surname and telephone fields filled.
The second Contact record has name, surname and email fields filled.
The part where merge occurs is below. The original code can bee seen from the link at the top.
When I run the example with following modifications, the e-mail address doesn't get merged into the new contact record. What I get is one merged Contact with the values from one of the records, with address data added, but no e-mail. I thought this was supposed to fill empty fields of the primary record with the non-empty fields from the second record.
Being very new to Ms Dynamics CRM, I couldn't understand the reason after much googling and debugging. I'll be glad if someone can give me some feedback about what the problem might be.
Thanks in advance.
_serviceProxy.EnableProxyTypes();
CreateRequiredRecords(); // created two contacts with same name, surname. first record has telephone1 filled, second record has emailaddress filled.
EntityReference target = new EntityReference();
target.Id = _account1Id;
target.LogicalName = Contact.EntityLogicalName;
MergeRequest merge = new MergeRequest();
merge.SubordinateId = _account2Id;
merge.Target = target;
merge.PerformParentingChecks = false;
Contact updateContent = new Contact();
updateContent.Address1_Line1 = "test";
merge.UpdateContent = updateContent;
MergeResponse merged = (MergeResponse)_serviceProxy.Execute(merge);
Contact mergeeAccount =
(Contact)_serviceProxy.Retrieve(Contact.EntityLogicalName,
_account2Id, new ColumnSet(allColumns: true));
if (mergeeAccount.Merged == true)
{
Contact mergedAccount =
(Contact)_serviceProxy.Retrieve(Contact.EntityLogicalName,
_account1Id, new ColumnSet(allColumns: true));
}
That behaviour would be as expected - the Merge will move over child records for you from the subordinate to the master (so potentially opportunities, addresses etc.) but not try to workout which fields you want copied over. The reasoning (I would guess) is the potential business logic implications are endless - do you want to copy over emails? what if all email fields are filled? what about custom fields? And lots of other cases I'm sure everyone can think of.
Edited:
To workaround this, there is a property on the MergeRequest class called UpdateContent. If you update fields on this property, the values will be merged into the parent record.
You can actually see this in the link you has posted:
// Create another account to hold new data to merge into the entity.
// If you use the subordinate account object, its data will be merged.
Account updateContent = new Account();
updateContent.Address1_Line1 = "test";

EF4 - Self tracking entities and inheritance and eager loading

I know this has been asked before in several ways but none of the answers seem applicable to me - or correct - or current, so I'll try again.
I have a large model with several intstances of inherited entities. One example is a Timetable that contains a collection of TimetableEvents. There are several sub-types of TimetableEvent, such as an InterviewTimetableEvent, BreakTimetableEvent and an ExercisetimeTableEvent. ExerciseTimetableEvent has a relationship to an Exercise entity.
I need to use self-tracking entities as I'm using a WCF back end to serve up data to several WPF clients in a stateless fashion.
So, I need to eager load everything and I thought that self-tracking entities would automatically do this but it appears they dont.
So, to get a timetable I need to do something like this:
var tt = (from s in ESSDataContainer.Timetables
.Include("TimetableEvents")
where s.TimetableId == timetableid
select s).FirstOrDefault();
This will give me the TimetableEvents but not the Exercises that are related to the ExerciseTimetableEvents. Ive tried the following (and several other suggestions) without luck:
var tt = (from s in ESSDataContainer.Timetables
.Include("TimetableEvents")
.Include("ExerciseTimetableEvents.Exercise")
where s.TimetableId == timetableid
select s).FirstOrDefault();
Is there a solution to this?
If not I'll go back to normal context tracking and connect to the database from a local container rather than using WCF.
Cheers
It's a bit tricky, but possible:
var tt = (from s in ESSDataContainer.Timetables
where s.TimetableId == timetableid
select new
{
TimeTable = s,
Events = s.TimeTableEvents,
Exercise = s.TimeTableEvents.OfType<ExerciseTimetableEvents>()
.Select(ett => ett.Exercise)
}).Select(s => s.TimeTable)
.AsEnumerable()
.FirstOrDefault();
Clear as mud, but, hey: No magic strings! Also, it has the advantage that it actually works....
There is a Proposal for this issua at Microsoft Connect:. If you think this worthy you can vote for it.

Resources