Andrey Markhel
unread,May 7, 2012, 10:51:05 AM5/7/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ActiveJDBC Group
Hi, Igor.
As I talk earlier I'd encountered some problems with AJ associations
in real-world relatively complex mappings. Let me explain by example.
1) There is entity Article in database, that entity should have 2
associations as one-to-one to table USER(author, editor). AJ can do it
by one-to-many association, but the problem there that both
associations has same type(User.class)
It is not possible for now to select right association via
Article.get(User.class), .include(User.class) etc..
It isn't rare case I think, for example in my project I have relations
- User - home adrress, billing address, etc.. or User - friends,
childs, parents, married, ignored users(self-referenced tables)
Yes, I saw your comments at 'One-to-many associations' page, and I
agree that there exist workaround - User author =
User.findByid(article.get("author_id")),
But I disagree with you, that this feature is complicated and not-
needed. Furthermore, I had implement this at local computer, but
unfortunatelly right after that computer was died:) Main point - is
add to all association one additional field -
"association_name"(optional), if that one isn't specified, "default"
association name is used. After that I rewrite a couple of methods
(include, get... ) and add to it one additional parameter
'association_name', for example
@BelongsToParents({
@BelongsTo(foreignKeyName="author_id",parent=User.class, name
="author"),
@BelongsTo(foreignKeyName="editor_id",parent=User.class, name =
"editor")
})
public class Article extends Model {}
and then author = Article.getAll(User.class, "author") editor =
Article.getAll(User.class, "editor"). My changes isn't break
compatibility, because getAll(User.class) is still worked (just
delegate to getAll(User.class, 'default')).
I think AJ will be only more powerful with that. I see one drawback -
there are need to add ~10 methods to Model.java and relatively
complicate API, but for me, additional power will outweight drawbacks.
Users will can map any associations in any way they want. Also, there
are no many effort with caching, cascade deletes etc.. because
associations has same type, if cache will be purged for one
association, it will be purged for second too. But, however, decision
by you. Also, I can commit my proposal and we can review. But at the
moment I want to know your thoughts about it, and if you completely
dislike it, I save big amount of time :)
2) Self-referenced tables, for example User has childs and has
parents, what this call will return? - User.include(User.class) :)