On Thu, Oct 30, 2008 at 1:47 AM, chris_g <[EMAIL PROTECTED]> wrote:
>
> Here is an example of a ManyToMany relationship that is derived from
> the elixir tutorial example.
>
> class Article(Entity):
> using_options(tablename='tbl_article')
> id = Field(Integer, Sequence('article_id_seq'),
> primary_key=True)
> doi = Field(Unicode(50), required=True, unique=True)
> tags = ManyToMany('Tag', tablename='tbl_article_tag')
>
> class Tag(Entity):
> using_options(tablename='tbl_tag')
> id = Field(Integer, Sequence('tag_id_seq'), primary_key=True)
> name = Field(Unicode(50), required=True, unique=True)
> articles = ManyToMany('Article', tablename='tbl_article_tag')
>
>
> I'd like the Foreign Key relation ship to be JOIN on the
> tbl_article.doi, rather than the tbl_article.id .
>
> That is rather than having a foreign key relationship like:
>
> CONTRAINT tbl_article_tags_fk FOREIGN KEY (id) REFERENCES tbl_article
> (id)
>
> I want to have:
>
> CONTRAINT tbl_article_tags_fk FOREIGN KEY (doi) REFERENCES
> tbl_article (doi)
>
>
> Is there an easy way to do this?
There is a way, though it's quite ugly because, for now, one doesn't
have easy access to the ManyToMany table. See attached file.
> I assume that this is what the
> primaryjoin argument does,
Indeed.
> but I am struggling to find the correct
> syntax for the filter argument.
>
> Is it easier and less confusing to explicitly declare an ArticleTag
> class that would give the equivalent behaviour.
Probably. In that case, I advice you to use an AssociationProxy on top
of that, to make your life easier.
There is also a third option available if you use Elixir's trunk,
which is to declare the ManyToMany table manually, and use the table
object explicitly in the relationship instead of using the table name:
tags = ManyToMany('Tag', table=article_tag_table)
--
Gaƫtan de Menten
http://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---