For Subsonic users,
is there a source of information about how to deal with many-to-many relations in Subsonic? I keep getting "//no ManyToMany tables defined (0)" in my generated code, although I have defined the right relations in database.
any help?
Check out Kent Sharkey's example at http://dotnetslackers.com/articles/aspnet/UsingSubSonicToCreateASimpleBogEngine.aspx. Specifically, look at the section titled "Adding Category support".
Numerous times, I have setup the keys incorrectly which has caused SubSonic to not recognize the many-to-many relationship. Make sure both fields make up a composite key.
Related
First time posting a question, here goes. I'm busy setting up a PowerBI presentation, and importing data from Excel Sheets. I'm doing environmental work, and so I need to relate projects occurring in a specific zone (from ZoneTbl) with activities (from ActTbl) occurring in that same zone. However, one zone can have multiple activities, and one activity can also be present in multiple zones. So the problem I'm having is defining many, many-to-many relationships between tables. I've tried "junction tables", where I have tried relating two foreign keys (in the form of the primary key from ZoneTbl, ZoneID, and the primary key from ActTbl, ActID). However, I still end up with some many-to-many relationships. I've been told this is poor databse modelling, and I'd like to do it correctly, and so any advice around defining these types of relationships, and specifically dealing with the problem of "zones having multiple activities and activities having multiple zones", would be appreciated.
Thanks!
I have a Core Data model that includes Document Entities and Quote Entities. There is a many-Quotes-to-one-Document Relationship in the model.
I am introducing a new type of Quote, so I would like to create a parent BaseQuote Entity, that will have TextQuote and ImageQuote 'child' Entities. The existing Quote will become a TextQuote.
So, I need to push the Quote side of the Relationship down the hierarchy into BaseQuote.
The lightweight migration documentation says that I can manage "changes to hierarchies" and "changes to relationships", but is not clear that it handles both at once!
If I check the mapping, Core Data thinks it is possible, inferredMappingModel does not throw an error:
NSMappingModel.inferredMappingModel(forSourceModel: lastVersion, destinationModel: thisVersion)
However, when I run the migration I get a crash with the message:
Validation error missing attribute values on mandatory destination relationship
It turns out the relationship is not being correctly populated by the migration - although structurally it seems to have worked.
Has anyone tried this before and got it working?
I think this is beyond lightweight migration. The page you link to explains that relationship changes include adding, deleting, renaming, and changing to-one to to-many or back. What you need is to move the relationship from one entity to a different one in the hierarchy, that is, take a relationship to Quote and move it to the new BaseQuote. It would probably be fine if you were changing the hierarchy and making one of those changes (renaming the relationship, for example). Lightweight migration doesn't cover re-targeting a relationship to a different part of the hierarchy, though.
I'm trying to start an application and my idea was to rattle off the entities first using the command line and then work on the UI. This is proving trickier than I first thought because under certain circumstances you get a warning saying the generator won't work. It's things like whether it's a OneToMany or a ManyToOne or whether this entity is the owning side of the relationship.
What's the best way around this?
If I can work out the rules then I can maybe decide what order to create things in. My worry is that with a complicated schema there is no order that can work without some warnings and things not working.
My other idea was to generate the entities without relationships first and then edit the json files to add the relationships. Then maybe I can run the generator again on each entity. Not sure if that would work though and I'm not 100% sure of the correct json properties required.
What have other people tried?
Plan your entities and relationships, so that when you create an entity all the entities it depends on have already been created. One way to do this is use a schema designer or just document the entities and put them in the order they need to be created.
Otherwise, as you know, you'll have to manually wire those relationships, or recreate them with the entity generator.
But, even with planning, you're going to have to use a mixture of these methods in the real world. It just depends on how much you've modified the generated code as to which method is the fastest.
Rori's answer is basically what I did but I wanted to provide some extra detail.
First I went through the generator and created every type of relationship to see which ones worked and which ones gave a warning. I was finding that sometimes it worked and sometimes it didn't but it wasn't documented anywhere why.
These relationships always work.
OneToMany
OneToOne (not owner)
ManyToMany (not owner)
These relationships only work when the other entity already exists.
ManyToOne
OneToOne (owner)
ManyToMany (owner)
The reason they don't work is always the same. All of these require a foreign key to be created on the other table which jHipster can't do if it doesn't exist yet. You could of course ignore the warning but I wasn't sure if this meant anything else wouldn't work.
Based on these rules I made a list of my entities and put them into an order that would work without warnings. If an entity had a relationship that may give a warning then I just made sure the other entity was created first.
This seems to have worked. The only thing I've found is that because the generator is a one time thing (you can't use it to modify an entity), you have to know your schema up front and generate the lot in one go.
I am trying to use the Entity Mapping Model to migrate my existing many-to-many relationships in my application. I have the following relationships
Teams <<----->> Players
A Team entity can have multiple players, and a Player can be part of several teams. Now, I am trying to split this relationships to one to many by introducing a new entity with the following properties
TeamToPlayer
Team *team
Player *player
So the new relationship will look like
Team <--->> TeamToPlayer
Player <-->> TeamToPlayer
I am trying to figure what kind of entity mapping should be I be using to transform my core data model. Is it possible to do the above using the Mapping model or do i need to write code by inheriting NSMigrationPolicy class.
Any thoughts would be very helpful.
Thanks,
Javid
After trying to understand the migration process and entity mapping models for couple of days, I finally managed to find a solution. I was surprised to find how simple it was.
I created two entity mapping with Source from Player & Team to TeamToPlayer and mapped the relationships from the source entity to the destination entity relationship.
And updated the relationship mapping names in the PlayerToPlayer and TeamToTeam relationship mapping to use the new entity mappings.
Everything just worked.
I've searched a lot and I haven't really found an answer.
Is it possible to use POCOs with Subsonic?
How do I map tables (which do not look like the POCOs) to my classes?
SubSonic doesn't provide a built in way to map tables to your POCOs.
The closest it would come would be using the ActiveRecord portion of SubSonic which would generate one class per table (with properties for each table column and foreign key relationship to other tables).
Depending on how your POCOs look, you might be able to get data easily (or not) between the generated ActiveRecord classes and your POCOs. Also, the generated ActiveRecord classes are created via templates which you can modify to fit your needs.