Hi Tibor,

On Mon, Aug 17, 2009 at 4:17 AM, gentlestone<tibor.b...@hotmail.com> wrote:
>
> I'm looking for a support for something like Eric Evans Value Objects
> (http://domaindrivendesign.org/). For example, if I have a Person
> model like
>
> class Adress(models.Model):
>    street = ...
>    city = ...
>    postal_code = ...
>
> class Person(models.Model):
>    home_adress = models.OneToOneField(Adress)
>    business_adress = models.OneToOneField(Adress)
>
> Adress is like a Value Object, but I don't want any adress table, nor
> extra foreign key and database joins. My application is not made for a
> National Post Office domain. I just want an Adress class whitout
> database identity.

I think you're approaching the problem incorrectly.  When dealing with
a relational database, go ahead and view things from a relational
perspective.  In this case, if you want your Person model to have
zero, one, or multiple Addresses, and a single Address can be used by
multiple people, what you want in Django is a ManyToMany field.  Yes,
this creates a couple more tables and the requisite joins, but as it
so happens, that likely won't be a problem for you, as you are writing
an application that is as you say "not made for National Post Office
domain."  In short, don't fight the relational model in this case.  It
is designed to handle such tasks.  The only reason you might want to
avoid an extra table or two is due to poor performance, but I suspect
that you are optimizing prematurely.  Until you have a large number of
users, you don't need to worry about one M2M field.  And your first
choices for optimization in Django should be caching and setting up a
separate image server, not database denormalization.

Django's ORM is a very powerful tool, and it makes the developer's
life a lot easier in many ways, but that in part is because the Django
developers made design choices that reflect best practices and channel
users in the proper direction.  The fact that Django does not make it
easy to do what you think you want is likely a sign that you are going
upstream against the natural flow of Django.  In short, take it as a
warning sign that you should rethink your approach.  Try working with
Address as a ManyToMany field, and see whether that works for your
application.  From there, if it presents a problem, you can always
rethink later, and you will have the benefit of knowing what problems
you need to work around.

Hope that helps,

---Peter

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to