I have posts documents and user documents how are authors of this posts. I need to get all posts which are at a given venue and for those posts the corresponding user/author documents as well.
Post:
{
"_id": "53551d9e92436f69ae04a104c2000b82",
"content": "heythere!",
"author": "a4df7fe1226fedb80f6c2dc13e000af5",
"venue": "51434246e4b0601fde0cf2eb",
"type": "post"
}
User:
{
"_id": "a4df7fe1226fedb80f6c2dc13e000af5",
"username": "sep o sep",
"type" : "user"
}
Is it possible to emit keys in the way that i will get posts to a given location along with the user documents to that posts in one couchdb query?
Check out the wiki, there's a feature called "linked documents" that allow you to retrieve related documents in a single view query.
The wiki will give a full explanation, but the gist is that you emit an object with an _id property in your view function for each related document. (since you have the id contained in your parent document) When include_docs=true is used in your view query, CouchDB knows to retrieve the documents you emitted rather than the source.
Related
I am trying to create list items with Microsoft Graph's new SharePoint endpoint. My URL is as follows:
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items
Calling this URL with POST, and a body like this:
{
"fields": {
"Title": "test",
}
}
.. works! But if I include a lookup field, the lookup field is always empty. I have tried with
"{columnName}": "id",
"{columnName}": "id;#value",
"{columnName}": {
"#odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", //and others like this
"Id": "id",
"Value": "value",
}
"{columnName}": "value",
"{columnName}Id": "id",
None of these seems to work. Some give an error like "The request is malformed or incorrect.", others go through, but doesn't include the lookup field.
The documentation for this is scarce (if any), and I have found very little information on google (apart from someone asking the same question with no answers). Anyone that got this to work yet? Is it even possible?
I have got this to work with people fields where the multiple selection option was DISABLED. So if you have a person field which allows one person only, the following works.
"{columnName}LookupId": id
Additionally, the id still needs to be the SP ID and not the graph user GUID. This ID changes from site to site.
You need to add a lookup column in the following format
"Office": "London",
"OfficeLookupId", "16"
Where Office is the name of the column
Using the OData standard is it possible to replace collection by sending a new collection?
Scenario:
The person object contains a list Address object. I would want to replace the Address collection with a new collection.
PUT Persons(1)/Addresses
[{"city": "X", "country": "US"}, {"city": "Y", "country": "US"}]
This is not possible out of the box (at least for ODATAv3), as the default routing template does not expect segments after the key portion.
But you should be able to add an ODATA Action that would do what you want to achieve. Your action definition could then look similar to this:
var action = builder.Entity<Person>()
.Action("Addresses")
.Returns<bool>();
action.Parameter<Collection<CityCountryPair>>("data");
The type CityCountryPair would be a regular DTO containing your properties you want to change. Make sure this type is also registered as an EntitySet in Odata or use a plain map/dictionary with only primitive types.
The actual call to the ODATA action would then look similar to this:
POST http://www.example.com/api/YourEndpoint/Persons(42)/Addresses
Content-Type: application/json
{
"data" :
[
{ "city" : "Berne" , "country": "CH" },
{ "city" : "Y" , "country": "CH" }
]
}
If you want to send more complex data types you can still resort to a customer JSON Deserialiser and override the default one or use a custom model binder after all.
I have a Contact model that has three attributes:
name, email, id
name and email are both present, but id is null.
I am using name and email to pass in through an API Post call, and this is the response I get back:
{"count": 1, "next": null, "previous": null, "results": [
{"id": 8067950, "name": "Bill","email": "test#test.com"}]}
My loop looks like this:
contacts_array.each do |contact|
api_call(contact.name, contact.email)
end
contacts_array is an array of ruby objects, namely Contact models. How can I, within that loop, assign the response id I get back to the contact used in the api_call?
I didn't really understand the difference between your Person and Contact model, but I'll assume they're the same model.
Generally you should know that it's a bad idea to handle the field called id on your own in rails. If you insist on storing the id which is returned from the call, then you should store it in another field, like api_id for example.
Below is a code that should work fine if api_call returns a Ruby Hash like the one in your question.
contacts_array.each do |contact|
contact.api_id = api_call(contact.name, contact.email)['results'].first['id']
end
I have two questions both relating the the User data sets.
1.
Is UniqueName in WhoAmI the same value as UserName in UserData
User.WhoAmIUser
{
"Identifier": "<string:D2LID>",
"FirstName": "<string>",
"LastName": "<string>",
"UniqueName": "<string>",
"ProfileIdentifier": "<string:D2LID>"
}
User.UserData
{
"OrgId": "<number:D2LID>",
"UserId": "<number:D2LID>",
"FirstName": "<string>",
"MiddleName": "<string>",
"LastName": "<string>",
"UserName": "<string>",
"ExternalEmail": "<string>",
"OrgDefinedId": "<string>",
"UniqueIdentifier": "<string>",
"Activation": "{composite:User.UserActivationData}"
}
2.
How can I retrieve the current authenticated users email address? I've tried to connect to various Users API's but all return "Not Authorized". Even the "/d2l/api/lp/(D2LVERSION: version)/users/(D2LID: userId)" with my userId authorized as myself throws Not Authorized.
I have tried both with Student and Instructor Roles. I can retrieve the WhoAmI service, just not any other User services.
Thanks.
1) The UniqueName property in the User.WhoAmIUser structure will (should) present the same value as the UserName property in User.UserData: this is the user's "log in name" within the LMS. In the back-end service, these two properties might be maintained separately, but for all intents and purposes, to the calling client, they should contain the same value (in that if you change the UserName value in a user record through the web UI, and then make a WhoAmI call, you'll see that change show up in the UniqueName property in the WhoAmI results).
2) Retrieving a user's email address may not be a simple feat: the ExternalEmail property in the UserData record should contain the same value that appears in the Email field in the user record in the Web UI. This is the email address that the LMS will use if it needs to send password-reset messages to a user.
This property is subject to User Information Privacy role-permissions, and some organizations may choose to tightly restrict who can see that value.
Additionally, the /d2l/api/lp/{ver}/users/ route itself is often subject to restrictive role permissions with some organizations. In general, if you're making a call with a user role that would have access to the functionality of the Users tool in the LMS' web UI, that role should also be able to have access to this API route.
If you do not have permission to use that API call (and you may not), then you can't use it to look for user details.
The User.User and Enrollment.ClasslistUser structures also contain a property to house that Email value from the user record, and if you can make a call to retrieve those structures (enrollment API calls, for example, or the classlist API call), then you might have access to the email value there, contingent on the User Information Privacy permissions the calling user has in place.
The upshot of all this is that many users at many organizations won't have the permission to retrieve their own external email address from their own user record, as they may not have permission to make the calls that would retrieve it, and it's not contained in the WhoAmIUser structure.
I have the following classes:
Hotel: ID, ..., IList<Photo> Photos
Photo: ID, Url
and in the database the corresponding "Hotels" and "Photos" tables and a link table in between that contains the IDs :
HotelPhotos: HotelPhotoID, HotelID (linked to PK HotelID from Hotels table), PhotoID (linked to PK PhotoID from Photos table)
The configuration file for Hotel class is :
...other fields mapped
<bag name="Photos" table="TravelRoutePhotos" inverse="true" cascade="all" lazy="false">
<key column="TravelRouteID" />
<many-to-many class="TravelAssistant.Model.HelperModels.Feedback.Photo" column="PhotoID"/>
</bag>
Whenever I add/update a hotel with a photo, I get correctly the inserted the Photo and Hotel data but the HotelPhotos table remains empty.
I have tried flushing the session after updating, tried setting the "bag" to "idbag" in config file , removing the "inverse" from config file but stil the same result.
Could someone help me out please?
Tamas
EDIT The HotelPhoto class does not exist; only the link table HotelPhotos.
Unclear whether you've edited incorrectly when changing your mapping, but from your code as it is your mapping entry should be
<bag name="Photos" table="HotelPhotos" inverse="true" cascade="all" lazy="false">
You also need to make sure that you're using hotel.Photos.Add(photo); or similar. You've definitely got the right idea about your mapping, and you shouldn't need the reference on Photo.hbm.xml so long as you don't want the Hotels collection in your Photo class.