Skip to content

Improved many-to-many support. #31

wants to merge 1 commit into from

2 participants

toots commented Jan 26, 2012

This PR provides an enhanced many-to-many support. It works that way:

Foo = FastLegS.Base.extend
  tableName  : "foos"
  primaryKey : "id"

Bar = FastLegS.Base.extend
  tableName  : "bars"
  primaryKey : "id"

FooBar = FastLegS.Base.extend
  tableName   : "foos_bars"
  foreignKeys : {
    model : Foo,
    key   : "foo_id" }, {
    model : Bar,
    key   : "bar_id" } ]

Foo.many = [ {
    bars  : Bar,
    assoc : FooBar } ]

Bar.many = [ {
    foos  : Foo,
    assoc : FooBar } ]

The old joinOn : "foo.bar_id" is dropped.

Also. includes.join is changed. It is now:

Foo.find { id : id }, {
  includes : {
    join : {
      model : Bar,
      key   : "foo_id"
}, ...

Hey toots! You made this request nearly a year ago. Our apologies for taking so long to respond. The code has diverged quite a bit since you made this pull request, including support for MySQL now.

However, I integrated your changes into the latest version as many-to-many relationships were basically broken and I like the syntax you proposed.

I'd like to give you the proper credit, but I am not sure of the best way. I acknowledged you in the comments, but if you'd like, you could do a new fork, update the file adding yourself as a contributor and then do a new pull request,

What do you think?

@dogeared dogeared closed this Dec 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.