I have a first table named "Building", and this one gets a Type and a Level. There are multiple building with same type and level.
I have another table named "BuildingInfo", who also gets a Type and a Level. The couple Type/Level is unique on this table.
Is there a way to have a HasOne relationship on Building, giving me the matching BuildingInfo ? The problem being that there are two keys on each table to get it, and I can only specify one key for each table with HasOne().
Thank you.
Related
I have two fact tables: FactSales & FactInvoices. Both have an foreign key relationship with DimDate.Datekey. In VS, the SSAS DSV displays these relationships (the lines are drawn between the tables).
In the DSV I decided to to create a named query that limits the dimdate to 2021. After doing this, I still see the relationships between the two fact tables and dimdate (which is now a named query).
At the DB-level, I created a 3rd fact table called FactExpenses. FactExpenses also has an FK relationship with DimDate.Datekey. The problem is that my dsv (in SSAS) does not recognize this relationship (ie. It doesn't draw the line between both tables).
Two questions: why doesn't VS display the relationship between my 3rd fact table with the named query but it does with the other two fact tables? I understand that the relationship isn't with the named query, but the relationship should disappear in all the fact tables.
When I want to limit the amount of data displayed in dimdate, should I use a named query?
The relationships in the DSV are separate to the foreign keys on the base tables, but they get added automatically based on the database schema when you add tables to the DSV. My guess would be when you added the initial dim and fact tables to the DSV in Visual Studio it automatically added the relationships based on the foreign keys that exist on the base tables, but this may not occur automatically for named queries. You can manually add the relationship yourself for the third table to get the same result.
I think a named query is a reasonable approach for the filtering you want to do. An alternative would be to create a view in the source database if you need to do more intense or complex filtering.
I have searched on the net but was not able to get an answer for my case. I am migrating a project on doctrine.
What is the correct way to link an entity to another entity that contains all the "families" of a project.
The families can be for instance :
"project_status" : status1, status2, status3
"countries" : en, us, cn ...
"tags" : tag1, tag2, ...
So all these values are stored in the same table in database and my entity handle this.
So now i have an entity that can have for example several countries or tags.
In the database i have one text field for the countries and one text field for the tags. And i store the ids of each tag or family inside these fields.
So let's say that I have one entity called "family" and one entity called "myEntity".
What is the best way to do ?
Ok maybe I have found one way in fact.
Instead of using my usual text field in my entity table to store the ids of the families I will use a join table.
So let's say that I have one table with my different lists in my project (country, file_status, and other possible lists). I will then have one entity for this table "familyEntity".
I will create a table that will be used for the cases in which one entityA can have several values of the same family (country for instance). In that case, I wil have a many to many association between familyEntity and entityA for that family.
If I have another entityB that uses the family "status" with several values possible, I will also have a many to many association using the same table for the association.
In the other cases in which only one value is possible for one family I will have many to one association.
Don't know if it is the right way but it occured to me that way. This solution seems ok for primary keys that are not compound).
In my database schema, I have multiple tables that hold generic data for objects, for instance I have a user table and a user_data, post table and post_data, and so. these *_data tables all hold a foreign key to the object and a pair of key-value. now in my laravel models I would like to have a single data models for these tables (rather than a model for every single one) and represent the has_many relation in a dynamic way where somehow I can define the table name according to the parent model. I think the parent model would have something like:
return $this->hasMany('data');
but I don't know how to express the inverse relation nor how to tell laravel which *_data table to use. so my question is, is it possible? and if so, how?
You have two options.
Either create a model for each data_* table and use the relation as stated with $this->hasMany('data'); and $this->belongsTo('User'); in the data table and the user table.
Or you can use Polymorphic relations, I personally prefer the polymorphic relations solution, more neat.
I'm using CodeIgniter and I'm starting to work with gas orm.
One of my m-n-relationship-tables using a composite key has also some additional attributes to the releation.
For Example:
Table teams, Table employees, and a m-n table which binds them together + adding the attribute role
Is it possible to get the attribute using GAS ORM?
Yes, it is possible.
Simply create a new relationship in one of the two tables you are going to link with the pivot table that refers to the pivot table itself as a has_many relation. (But dont do the linking stuff in the model file, eg:
ORM::has_many('\\Model\\User\\Role')
instead of
ORM::has_many('\\Model\\User\\Role => \\Model\\Role')
See http://ellislab.com/forums/viewreply/1050559/ for exact the same question.
I am using Database First EF to generate model from the existing database. When I first generated the models, it ignores only one of the table, the entity was not added to EDMX, no model file is created for the table and no context is created for the entity.
When I tried to explicitly add the table to EDMX (when generating the model, selected the specific table first and then updated the model with all the other tables from the database), it complained with the following error.
Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
This specific table has two columns which are primary keys of some other tables and both the columns are specified as Primary keys for the table.
Am I doing something wrong or should I handle this table differently since it has two columns defined as Primary Keys? Any suggestions greatly appreciated!
You are not doing anything wrong. Your table is junction table for many-to-many relation. You don't need that table in the model because EF (in contrast to database) can handle many-to-many relation directly without any intermediate. The table is actually mapped on behind of the many-to-many relation - you will see that in mapping details window.
Btw. you are not using code first. Code first = no EDMX.