How to select fields from related tables in dreamfactory - select

I am playing with the DreamFactory Schema and API Docs. Within the Schema i add a "Virtual Relationship". Now in API Docs i put the name of the Virtual Relationship in related, on execute everthing is fine. I'll get the fields from the related table. But i dont need all fields from the joined table. How to select only the fields i need? I try to add "name_of_related.field" under "fields".
Error:
"message": "Invalid field requested: fe_users_by_fe_user_id.username"

add <relation_name>.fields=fieldname1,fieldname2
in my case:
/api/v2/myservice/_table/mytable?fields=uid,tstamp&related=fe_users_by_fe_user_id&fe_users_by_fe_user_id.fields=username

Related

How to query a parent table and inherited child table together in one query

I am using go and pq to interface with my postgres database.
I have a simple user table which has basic fields. Id, name, type. My auxillary table, admin inherits from user and adds it's own field panel, and another one that is owner and adds owner. Whether that be using table inheritance, or a supporting table.
My question is if I hit and endpoint that points to user/1 at this point I don't know what type of user this person is yet here. I know we can use jwts and other ways to provide this from the front end. I'm more curious about if there is a way to figure out the user and it's type and query the additional fields in one query?
Ie. I hit the endpoint I would Select from users, get the type, then use that type to get the additional fields. So I would effectively be doing two queries on two tables to get the complete data. Is there a better solution of doing this? Is there some optimizations I could do.

Get Mongoose to automatically create joined document

I have 2 Mongoose.js Schemas that work together with the 'populate' feature: A 'user' schema and another based on their role. E.g. 'admin'. When a user is assigned a role, a corresponding document needs to be created in a different collection with a link to the _id of the document in the users collection. (Yes, more like an SQL database than non-relational, I know)
Currently I manually create the second document in my code whenever a user with a specialized role is created or a role is added to a user. |
I'd like to know if there is a way to automatically create this corresponding record from my schema whenever a 'user' document is created or updated with a role.
Any advice?
Nothing will do it automatically, but you can use the mongoose middleware to insert our update a document in another collection pre or post save.
The post hook will have the _id populated.
If you want to do it in the pre hook (to enforce some transactional integrity) you can assign the _id manually.

Entity Framework "Invalid object name 'Item_id'"

I have a solution that has spontaneously started generating the error "Invalid object name 'Item_id'". I have searched for this but all answers seem related to code first issues around pluralization; my project is database first.
The context is that there is a Purchase with a collection of ItemPurchaseLines which are linked to Items. The error occurs when a new purchase is generated, this generates new ItemPurchaseLines and either links them to existing Items or generates new Items. The mapping between ItemPurchaseLines and Items is via a foreign key on Item_Id to Id respectively.
I have regenerated the model from the database and the relationships/column mappings all look good.
Any help, or any further information you need, would be appreciated.
Edit
I have built a LinqToSql alternative and it gives exactly the same error.
OK - I am a complete idiot!
I completely forgot that I added a trigger to the relevant table to update the pl_Items table but instead of using the correct table name I used Item_Id.
So the code from VS was all good it was the SQL Trigger in the back and that was screwing things up!

Removing Entities from Database table via Navigation Property using RIA Services and Entity Framework

I have 3 normalised tables consisting of Employees, Departments and EmployeesToDepartments. I wish to be able to assign an Employee to one or more Department, hence the link table (EmployeesToDepartments). I can successfully query the database and extract the full hierarchy of entities via the Navigation properties using
this.ObjectContext.Employees.Include("EmployeesToDepartments").Include("EmployeesToDepartments.Department")
plus the [Include] attribute in the metadata, thus allowing me to access the Departments for a given Employee. Upon trying to remove a link between an [Employee] and [Department] in the [EmployeesToDepartments] table I was given a Foreign Key Constrain error.
I have simplified my model to include just one navigation property between [Employees] and [EmployeesToDepartments]. A Foreign Key constraint between[Employees].[ID] and [EmployeesToDepartments].[IDEmployee] was preventing me from updating the EmployeesToDepartments table. With this removed via a Relationship setting I can now update the table. I can now execute the following code
foreach (var rel in _employee.EmployeesToDepartments)
{
_employee.EmployeesToDepartments.Remove(rel);
}
_domainContext.SubmitChanges();
without error.
I was expecting to see the entries in the RelEmployeesToDepartments with the IDEmployee to have been deleted. What I see in the table are the value 0 where the IDEmployee previously was.
Is it possible to force a DELETE statement to be issued? Am I misunderstanding the basic concepts here?
Any help would be much appreciated.
Removing entities in navigation property only breaks the link between entities. You have to delete from the EntitySet to achive what you want.
ex)
myDomainContext.EmployeeDepartments.Remove(employeeDepartmentToRemove);
myDomainContext.SubmitChanges();

Adding a property to an Entity Framework Entity from another table

I'm just starting out with the Entity Framework and ADO.NET Data Services and I've run into an issue that I can't seem to figure out. I have two tables, one that has user information and the other that has a created by field. Within the database, there isn't a foreign key between these tables. The user table contains an arbitrary Id, a username, and a display name. The created by field contains the user's username. In my entity I would like to have the user's display name since this is what I need to display and expose over the ADO.NET Data Service? I'm aware that I could restructure the database, but I was hoping that I could do the join using the username as I would in a SQL statement.
Thanks in advance,
-Damien
You can make a view using a join of both tables, and then use this object to display the user's name.
There's some info on mapping custom queries here.