0

Is it possible to embed a form for an object that is related to another but the relationship cannot be managed by an entity manager? From the linked question: the Client entity is in a foreign database yet should have a one-to-many relationship with the Member entity. The objective is to build a form in which a client and its related household members can be added or edited. Or is the only feasible solution to persist the client then add the members?

Community
  • 1
  • 1
geoB
  • 4,578
  • 5
  • 37
  • 70

1 Answers1

0

This is very difficult. You will need to persist the user and the clients as you say, but managing related entities across databases makes eager loading impossible, which means you get an extra query for each related entity in list view. If you can use separate schema in the same database, then this problem is much simpler.

That being said, it is not hard to create a second form in your controller and render both in the template. Alternatively you can use a choice control and have a query generate a list of possible foriegn keys and store them as number types in your database.

I'd need to seem example code/controllers if you want precise advice.

Lighthart
  • 3,648
  • 6
  • 28
  • 47
  • The difficulty has become painfully obvious. The problem arises because my NGO client wants to share people data with other NGOs in their collaborative db and retain their confidential data elsewhere. If there was some way to clone an object to a different namespace I might get somewhere. Can this be done? – geoB Apr 16 '13 at 21:59
  • In the past, I have solved this problem by querying both sets of entities and manually forming the associations in memory. Tedious but effective. You may make methods for such associations in the entity codes and link them at runtime rather than via database connection. Again, without specifics it becomes difficult to describe. – Lighthart Apr 16 '13 at 22:35
  • If only I knew exactly what they intend to do. I'm just trying to get a grasp on the principles. But I think you've captured it - especially the tedious part. Off now to more tedium and experimentation! – geoB Apr 16 '13 at 22:44
  • I'll accept because you set me on the right track. I hope. Tests so far are promising - a class with properties/getters/setters of the foreign entity and that also extends local entity class with all the relationships. – geoB Apr 16 '13 at 23:45