Eloquent Relations one to many - one-to-many

I would use some help. I'm very new to Laravel,and trying to make Api. So,i have two tables,restaurants and categories. Restaurant Controller works fine,diplay data,store,update,delete,all. But Category Controller have problem storing new category,I'm getting error that function I made for relations in Restaurant Model is undefined when I'm testing it in Postman.
type here
I tryed everything,reading the documentation,search for the solution on google and You Tube,but nothing work

Related

Right way to model relationship in Entity Framework Core

I'm working on an ASP.Net Core MVC 2.0 application using Entity Framework Core 2.0. I need to upload a file related to an entity that is getting created by this application.
For example, imagine having to upload an invoice PDF as part of creating a payment entity. This should be a one-to-one relationship.
I'm having some trouble deciding how this should be represented in the Entity Framework data (and object) model. I found some guidelines that say that the entity foreign key should exist on the dependent object. In this case, the invoice would be the dependent object, so I should add the payment ID to the invoice object.
But I won't be downloading the invoice object as often as I would the payment object. And I was planning on a flow where the payment view would have a link to an action on the invoice controller to download the invoice using the invoice ID. So having the Invoice ID on the Payment object would make sense.
So I'm not sure of the best way to handle this.
As an aside, I've seen plenty of samples with uploading/downloading files, but not many that shows them how this might look when the files are associated with an entity in the database.
Does anyone have any suggestions?
I don't have any code that I can share at the moment; if anyone thinks code might help, I can throw something together.
Thanks in advance!
Just wanted to point out that Gert Arnold's comment was the correct answer; the following has examples of how to model one-to-one relationships.
https://learn.microsoft.com/en-us/ef/core/modeling/relationships
Thanks Gert!

How to get the list of all User stories including child stories using /slm/webservice/v2.0/hierarchicalrequirement API

I am using this rally API to get the list of all the stories:
https://rally-n.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?query=(Project.Name="My_Parent_Project")&order=OrderString
My_Parent_Project actually do not have any user stories, but its children projects (my_child_1 and my_child_2) has user stories.
Is there any specific field, which I can mention to get all the user stories including child projects.
I can see Rally UI has option to get the data from Child project. So I believe there must be an option to get this data using above API. (They use projectScopeUp=false&setScopedDown=true which doesn't seems to be working with
"hierarchicalrequirement" API.
You're really close.
It seems like you've already found the project scoping docs:
https://rally1.rallydev.com/slm/doc/webservice/projectscope.jsp
I think if you just swap your (Project.Name = "My_Parent_Project") query to instead use the project=/project/12345 query string parameter and include projectScopeDown=true you should be all set.

User stories and defects in one grid

I am trying to create a gird of user stories and defects together so that they can be properly prioritized by our product owner. I have tried using the 2.0 API to do this but have hit a wall. Looks like the Rally.ui.grid.Grid requires a single model but there are no model types that can be used to mix both User Stories and Defects together.
I tried using the getModels method but that only creates two distinct models and the grid doesn't like that. The grid requires only one model.
I have also tried creating my own model based on Artifacts but to register that with the ModelFactory I have to create a factory class which I don't know how to do.
Is there another way to do this given the 2.0 API?
You may use use Rally.data.wsapi.artifact.Store instead of Rally.data.wsapi.Store. See an example in this github repo.
var myStore = Ext.create('Rally.data.wsapi.artifact.Store',{
models: ['User Story', 'Defect'],
autoLoad:true,
//...
});

Rally SDK 2: how to get PortfolioItem/Initiative from user story

I want to query for user stories and the Initiative that each story falls under. My fetch property looks like:
...
model: 'UserStory',
fetch: ['Name', 'PortfolioItem', 'Parent'],
...
This fetches the PortfolioItem/Feature object, PortfolioItem/FeatureGroup object but not the PortfolioItem/Initiative. The FeatureGroup object does not show a 'Parent' property.
In short, how can I fetch the parent's parent without querying separately for Initiatives and comparing the '_ref' or something like that?
For server performance reasons the hierarchical relationships will only be populated for one level with each request. You'll have to make subsequent requests to build the remaining tiers.
If you hit the new Lookback API (unreleased when Kyle first answered, now in open preview), the snapshots returned include a field _ItemHierarchy which will include the ObjectID of all ancestors including all the way up through Portfolio Items.
You can find information on the LBAPI here. There is support for querying it in the App SDK 2.0's SnapshotStore. Note that SDK 2.0p6 (releasing soon) has some improvements.
Old, old question. But I recently did the same thing for the entire tree. I didn't use the lookback api. I created a model and stored the data and went through the parentage of each portfolio item.
Perhaps not the most efficient way, but it works.

Data Mapper API - unsure about organisation

Let's say we have "User" and a "Hotel" model classes. I'd use a User_Mapper and Hotel_Mapper to load/save/delete etc. I want to then have the user be able to mark their "favourite" hotels. In the database I have my user_favourite_hotels table which is a simple link table along with say a field for subscribing to hotel updates.
When listing out the user's favourite hotels, how would you expect this to work from an API point of view? A part of me thinks that this should be a "findFavouritesByUserId" method on the Hotel_Mapper, but other than saying it "feels" right - however a colleague suggests that the "favourites" is owned by the user and should therefore be on the User_Mapper.
Perhaps I should have a User_Hotel_Favourites_Mapper? I was thinking of incorporating the "favourites" data in to the User object so it's saved and loaded whenever the User object is. I'm not sure whether it'd be better to split it out in to it's own object and mapper however.
I'd appreciate any advice on how best to setup the API for the above and any pros/cons/experiences.
Thanks very much,
James.
This (admittedly retired) patterns&practices guide to designing data tier components suggests that you put the method in the mapper of the type of object that you're getting back from the call.
If you have methods that return a particular type of business entity, place these methods in the Data Access Logic Component for that type. For example, if you are retrieving all orders for a customer, implement that function in the Order Data Access Logic Component because your return value is of the type Order. Conversely, if you are retrieving all customers that have ordered a specific product, implement that function in the Customer Data Access Logic Component.
So, in your example, it would go in the Hotel Mapper as it is returning Hotels.
If you want to store favorite hotels for the user, you are using the UserMapper, which notices that domain object for User has changes favorites, and updates both tables for users and for user_favorite_hotels ( you just need the hotel IDs ).
When you are retrieving favorite hotels of some user, you use HotelMapper and set filter to be based on User, because you will be working with instances of Hotel.
Considering that this was asked more than 2 years ago, I'm not sure if an answer matters to you now. But here's what I think anyway.
If User could have multiple types of favourites (including Hotels), it may make sense to have a UserFavourites abstraction to cover all possible types of favourites. UserFavourites could expose a getItems() method to get the underlying Favourites.
This could be managed with the help of a manager class to return the appropriate Favourites object(FavouriteHotels for example) on which the getItems() method can be called.