Ext 4.2 hasOne association foreignKey - extjs4

I have two models with a hasOne association.
But, when I try to get the associated model using the getter method (extdirect), the foreignKey isn't automatic populated.
Should I expect that?
The hasMany association seems to be working well (I have the foreignKey automatic set by the framework).

Related

Doctrine 2 : Best way to manage many-to-many associations

Doctrine2 ORM have 2 technical ways to handle many-to-many associations :
1/ For a "simple" relation between 2 entities, and without additionnal attribute :
Use #ManyToMany associations between entities
In this case, the link table is used directly, without an association entity
2/ When link table introduces extra fields or more than 2 entities :
Use an association class, ie an "real" entity to map the link table
In this case, the direct ManyToMany association is replaced by OneToMany/ManyToOne associations between the participating entities
These 2 implementations are quite different.
But, in some cases, future business requirements can quickly need to change simple associations, by adding extra fields for example.
In this case, we must replace direct ManyToMany associations in existing entities by the second implementation and refactor affected code.
So, is it a good way to always use association entities to handle all
ManyToMany associations ?
Otherwise, what are the best practices for
choosing the good implementation and handle these kind of domain
model evolutions ?
If you have a good reason to belief that in the near future you will have extra properties on your ManyToMany join table then it's a good idea to make an entity out of precaution. If not then it's better to use the normal ManyToMany relationship. Then when a change is needed you can update your schema along with your code. If you try to follow the Single responsibility principle then you can avoid refactoring large amounts of code.

Fluent NHibernate mapping of a bi-directional, many-to-many association using an association class

I have a bi-directional, many-to-many association between EntityA and EntityB and I’m using an association class, EntityABLink, to model this because there are other attributes about the relationship that I need to track. In addition, I also have another class that holds a reference to a specific relationship between EntityA and EntityB so I treat the association class as a full-fledged entity.
In EntityA I have a read-only property that returns a list of associated EntityB objects and, likewise, in EntityB I have a read-only property that returns a list of associated EntityA objects. Note that, for these properties, I’m hiding the fact that the association is implemented via an association class. (I also have dedicated methods for updating the relationships that hide the implementation.) Behind the scenes in both EntityA and EntityB, I have private collections of type EntityABLink.
Since a picture is worth a thousand words, here is what I have described so far:
(Note again that the public, read-only properties on EntityA and EntityB are not of the same type as the private members that back them up.)
So far, so good. Now I want to persist these objects to a database using Fluent NHibernate automapping overrides. When it comes to mapping, I like to think of the above using this functionally equivalent representation:
From this diagram, it’s clear that what I really need is two bi-directional one-to-many relationships.
In mapping the above, I figure that I need something like this:
In the EntityA automapping override:
mapping.HasMany<EntityABLink>(Reveal.Member<EntityA>(“_AssociationList”)).Inverse().AsBag().Cascade.SaveUpdate();
mapping.IgnoreProperty(x => x.EntityBList);
In the EntityB automapping override:
mapping.HasMany<EntityABLink>(Reveal.Member<EntityB>(“_AssociationList”)).Inverse().AsBag().Cascade.SaveUpdate();
mapping.IgnoreProperty(x => x.EntityAList);
In the EntityABLink automapping override:
mapping.References<EntityA>(x => x.EntityA).Not.Nullable();
mapping.References<EntityB>(x => x.EntityB).Not.Nullable();
When I try this, however, I get the following error:
"Could not find a getter for property '_ AssociationList’ in class 'EntityB'."
I must have something wrong with my mappings, but I’m not sure what. Any ideas?
I got it working now. So here's the trick... I reverted back to Fluent NHibernate version 1.1 (specifically 1.1.0.685). Then, although the mapping examples that use "Reveal.Member" don't show it as being necessary, I added "Access.Field()" to the mapping for both EntityA._AssociationList and EntityB._AssociationList. Here are the working mappings.
In the EntityA automapping override:
mapping.HasMany<EntityABLink>(Reveal.Member<EntityA>(“_AssociationList”)).Inverse().AsBag().Cascade.SaveUpdate().Access.Field();
mapping.IgnoreProperty(x => x.EntityBList);
In the EntityB automapping override:
mapping.HasMany<EntityABLink>(Reveal.Member<EntityB>(“_AssociationList”)).Inverse().AsBag().Cascade.SaveUpdate().Access.Field();
mapping.IgnoreProperty(x => x.EntityAList);
In the EntityABLink automapping override:
mapping.References<EntityA>(x => x.EntityA).Not.Nullable();
mapping.References<EntityB>(x => x.EntityB).Not.Nullable();
Once it was working in FNH 1.1, I tried upgrading to FNH 1.2. No good. I tried 1.2.0.694 as well as 1.2.0.712 and both of these still give the incorrect error message that a different "entity" (which is actually an enum!) doesn't have an Id mapped.
Fluent NHibernate is a wonderful tool so I hope that the bug in the latest version gets fixed. :-)

Rails Controller: Is it good practice to define controller for associations?

Suppose i have mapping table map_user_roles. I have defined models Role and User. Both are associated to each other by relationship has_and_belongs_to_many. Of course it does not make sense to define model for mapping table in rails.
I have defined users_controller and roles_controller for crud operations on user and role respectively.
For association of user-role, what should i do? Should i define separate controller like user_roles_controller or should i make modifications in Role and User controller(if so how to do so) ?
Please suggest, what is good practice. Examples and good links would be great help
Thanks for devoting time.
I don't see what a separate controller for the association would offer that couldn't be achieved with your existing UsersController and RolesController. Also, note that sometimes is does make sense to define a model for the mapping table, that's what the has_many :through association is for. You should use it if you need to store extra attributes against the join model.

Creating a many-to-many relation between an entity and an another many-to-many relation with (N)Hibernate

I'm trying to create a many-to-many association between an entity and another many-to-many association. How can that be done?
I followed the Customer/Order/Product example to attach custom properties to a many-to-many association between two of my entities (Categories and Tags). That worked like a charm.
The problem is that now I need another entity (Supplier) to have many-to-many relation with Category-Tag-Relation, which was implemented as a composite-element according to that example.
But as far as I can see composite-element cannot participate in a many-to-many relationships :(.
The whole idea of what am I trying to achieve is depicted below:
schema http://img695.imageshack.us/img695/6315/schemag.png
You should map CategoryTagRelation as an entity. That will solve your issue completely.

Fluent NHibernate auto mapping - how to create a many-to-many relationship table?

just wondered if anyone know if there is a way to crate a Many-to-Many relationship table automatically using some attribute? without creating the table, or mapping a class to become that relation table.
If i add the attribute [ManyToMany(3,Class="DeploymentListUsers")] i get an error that this class isn't mapped to the DB.
NHibernate.MappingException: An
association from the table Users
refers to an unmapped class:
I don't want to define the class myself, nor creating the table in the DB before hand.
it's seems possible in JAVA, does fluent NHibernate is a fully implemented version of hibernate and JPA annotations?
http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=19mappingmanytomanyrelationships
Thanks,
Itay
If you specify a class, you must make sure it exists too. NHibernate will not create a class for you. If however, your many-to-many table only contains a foreign key to your deployments table and a foreign key to your users table, you won't need such a class. You will only need a separate many-to-many mapping class if you want to store additional facts about the relation.
As far as I can tell, in your situation you just need to create the many-to-many table (you could use NHibernate's SchemaExport() to generate the CREATE TABLE statement so there's some automation there) and tell NHibernate how to map to it. Unlike you, I don't use mapping attributes so I don't know how to do map using them but it is probably very simple.
NHibernate now supports JPA (called NPersistence or NPA for the .NET platform) including JPA annotations.
It is the best way to specify relations and have your code portable for other vendors as well.
check it out:
www.npersistence.com
My answer to a similar question might help you out: https://stackoverflow.com/a/12198533/185200
I ended up extending the many-to-many automapping step to support properties decorated with a custom attribute.