Discussion:
many_to_many with an extra column in the joining table
Clive Crous
2009-07-11 08:40:47 UTC
Permalink
Hi,

Imagine the scenarios where I have 3 tables => :foos, :bars, :foos_bars
I have 2 (perhaps 3) models => Foo, Bar (, FooBar)

and the Foo model looks like this =>

class Foo < Sequel::Model
many_to_many :bars, :join_table => :foos_bars, :class => 'Bar'
end

Within 'foos_bars' I have a column which describes the relationship
between Foo and Bar so :foos_bars's schema is something like:
{
foreign_key :foo_id, :table => :foos, :null => false
foreign_key :bar_id, :table => :bars, :null => false
varchar relationship, :size => 32, :null => false
}

My problem is as follows, how can I use foo.add_bar when there's
column data required in the joining table, for example:
{
foo = Foo.create( ... )
bar = Bar.create( ...)

# foo.add_bar( bar, :relationship => "baz" ) # Unfortunately this
does not work

foo.add_bar( bar ) # How do I do this? where do I describe relationship?
}

Thanks,
Clive
Jeremy Evans
2009-07-11 18:55:39 UTC
Permalink
Hi,
Imagine the scenarios where I have 3 tables =>   :foos, :bars, :foos_bars
I have 2 (perhaps 3) models => Foo, Bar (, FooBar)
and the Foo model looks like this =>
class Foo < Sequel::Model
  many_to_many :bars, :join_table => :foos_bars, :class => 'Bar'
end
Within 'foos_bars' I have a column which describes the relationship
{
  foreign_key :foo_id, :table => :foos, :null => false
  foreign_key :bar_id, :table => :bars, :null => false
  varchar relationship, :size => 32, :null => false
}
My problem is as follows, how can I use foo.add_bar when there's
{
  foo = Foo.create( ... )
  bar = Bar.create( ...)
  # foo.add_bar( bar, :relationship => "baz" ) # Unfortunately this
does not work
  foo.add_bar( bar ) # How do I do this? where do I describe relationship?
}
There have been various hacks discussed, but the current best solution
is to use a real model for the join table:

class FooBar < Sequel::Model(:foos_bars)
many_to_one :foo
many_to_one :bar
end
class Foo
one_to_many :foo_bars
def add_bar(bar, values={})
foo.add_foo_bar(FooBar.new(values.merge(:bar=>bar)))
end
end

This isn't an optimal solution as callbacks, reciprocals, and caching
are probably not handled as expected.

One way to do what you want is to have the add_*/remove_*/remove_all_*
methods take additional arguments, and pass those arguments down to
_add_*/_remove_*/_remove_all_*. Then you could just do:

class Foo
def _add_bar(bar, values={})
DB[:foos_bars].insert(values.merge
(:foo_id=>id, :bar_id=>bar.id))
end
end

I'm not opposed to a patch that does that, assuming it came with
decent specs.

Jeremy
Clive Crous
2009-07-11 19:52:47 UTC
Permalink
Post by Jeremy Evans
I'm not opposed to a patch that does that, assuming it came with
decent specs.
By "that" do you mean a patch that explicitly limited arguments to a
single hash or something a lot more generic like *args?

Clive
Jeremy Evans
2009-07-11 20:52:26 UTC
Permalink
Post by Clive Crous
Post by Jeremy Evans
I'm not opposed to a patch that does that, assuming it came with
decent specs.
By "that" do you mean a patch that explicitly limited arguments to a
single hash or something a lot more generic like *args?
I was thinking *args. If we are going to add additional flexibility
in this area, there's no reason to restrict it to a single hash.

Jeremy
Clive Crous
2009-07-11 20:58:44 UTC
Permalink
I was thinking *args.  If we are going to add additional flexibility
in this area, there's no reason to restrict it to a single hash.
I thought so too, however I thought best to make sure. One never knows
what's possibly planned "down the line" in a project you're not
directly involved in ;)

Thanks,
Clive
Scott LaBounty
2009-07-12 02:45:09 UTC
Permalink
OK, I'm getting confused with the foo, bar, baz thing. I'm trying to do
something very similar (in fact I was going to ask before I saw this
thread). I have a library app. with books and locations. Each book can have
many locations and each location can have many books. What I'm trying to add
is a "total" and a "checked_out" value for each book at each location. Based
on the above, what I have for my tables are (from my migration):

create_table(:books) do
primary_key :id
String :title
end

create_table(:locations) do
primary_key :id
String :location
end

create_table(:books_locations) do
primary_key :id
foreign_key :location_id, :locations
foreign_key :book_id, :books
Integer :total
Integer :checked_out
end

and my models:

class Book < Sequel::Model
many_to_many :locations
end

class Location < Sequel::Model
many_to_many :books
end

class BookLocations < Sequel::Model(:books_locatons)
many_to_one :books
many_to_one :locations
end

The BookLocations is what I gather from Jeremy's post that I need (should
those lines be "many_to_many" though?

Now though, I'm not sure what I need to add to the Book model to let me add
count and checked_out values (and change them) for a given destination.

Thoughts?

Scott
Post by Clive Crous
Post by Jeremy Evans
I was thinking *args. If we are going to add additional flexibility
in this area, there's no reason to restrict it to a single hash.
I thought so too, however I thought best to make sure. One never knows
what's possibly planned "down the line" in a project you're not
directly involved in ;)
Thanks,
Clive
--
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To post to this group, send email to sequel-talk-/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jeremy Evans
2009-07-12 05:39:58 UTC
Permalink
Post by Scott LaBounty
OK, I'm getting confused with the foo, bar, baz thing. I'm trying to do
something very similar (in fact I was going to ask before I saw this
thread). I have a library app. with books and locations. Each book can have
many locations and each location can have many books. What I'm trying to add
is a "total" and a "checked_out" value for each book at each location. Based
        create_table(:books) do
            primary_key :id
            String :title
        end
        create_table(:locations) do
            primary_key :id
            String :location
        end
        create_table(:books_locations) do
            primary_key :id
            foreign_key :location_id, :locations
            foreign_key :book_id, :books
            Integer :total
            Integer :checked_out
        end
class Book < Sequel::Model
one_to_many :book_locations
    many_to_many :locations, :join_table=>:book_locations
Post by Scott LaBounty
end
class Location < Sequel::Model
one_to_many :book_locations
    many_to_many :books, :join_table=>:book_locations
Post by Scott LaBounty
end
class BookLocation < Sequel::Model
   many_to_one :book
   many_to_one :location
Post by Scott LaBounty
 end
The BookLocations is what I gather from Jeremy's post that I need (should
those lines be "many_to_many" though?
Now though, I'm not sure what I need to add to the Book model to let me add
count and checked_out values (and change them) for a given destination.
Thoughts?
The association modification methods are fairly generic, for domain
specific behavior like you probably need, you probably should write
your own methods that use the BookLocation model. Something like:

class Location
def purchase(book, copies=1)
bl = book_location(book)
bl ? bl.update(:copies=>bl.copies+copies) : BookLocation.create
(:book=>book, :location=>self, :total=>copies, :checked_out=>0)
end
def sold(book, copies=1)
bl = book_location(book)
bl.update(:copies=>bl.copies-copies)
end
def checkout(book)
bl = book_location(book)
bl.update(:checked_out=>bl.copies+1)
end
def checkin(book)
bl = book_location(book)
bl.update(:checked_out=>bl.copies-1)
end
def book_location(book)
book_locations_dataset[:book_id=>book.id]
end
end

That's just a guess based on the probable needs of your app.

Jeremy
Scott LaBounty
2009-07-12 17:17:54 UTC
Permalink
Jeremy,

Thanks I'll mull that over and see what I can do with it. I appreciate all
the help.

Scott
Post by Jeremy Evans
Post by Scott LaBounty
OK, I'm getting confused with the foo, bar, baz thing. I'm trying to do
something very similar (in fact I was going to ask before I saw this
thread). I have a library app. with books and locations. Each book can
have
Post by Scott LaBounty
many locations and each location can have many books. What I'm trying to
add
Post by Scott LaBounty
is a "total" and a "checked_out" value for each book at each location.
Based
Post by Scott LaBounty
create_table(:books) do
primary_key :id
String :title
end
create_table(:locations) do
primary_key :id
String :location
end
create_table(:books_locations) do
primary_key :id
foreign_key :location_id, :locations
foreign_key :book_id, :books
Integer :total
Integer :checked_out
end
class Book < Sequel::Model
one_to_many :book_locations
many_to_many :locations, :join_table=>:book_locations
Post by Scott LaBounty
end
class Location < Sequel::Model
one_to_many :book_locations
many_to_many :books, :join_table=>:book_locations
Post by Scott LaBounty
end
class BookLocation < Sequel::Model
many_to_one :book
many_to_one :location
Post by Scott LaBounty
end
The BookLocations is what I gather from Jeremy's post that I need (should
those lines be "many_to_many" though?
Now though, I'm not sure what I need to add to the Book model to let me
add
Post by Scott LaBounty
count and checked_out values (and change them) for a given destination.
Thoughts?
The association modification methods are fairly generic, for domain
specific behavior like you probably need, you probably should write
class Location
def purchase(book, copies=1)
bl = book_location(book)
bl ? bl.update(:copies=>bl.copies+copies) : BookLocation.create
(:book=>book, :location=>self, :total=>copies, :checked_out=>0)
end
def sold(book, copies=1)
bl = book_location(book)
bl.update(:copies=>bl.copies-copies)
end
def checkout(book)
bl = book_location(book)
bl.update(:checked_out=>bl.copies+1)
end
def checkin(book)
bl = book_location(book)
bl.update(:checked_out=>bl.copies-1)
end
def book_location(book)
book_locations_dataset[:book_id=>book.id]
end
end
That's just a guess based on the probable needs of your app.
Jeremy
--
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To post to this group, send email to sequel-talk-/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Scott LaBounty
2009-07-14 15:52:27 UTC
Permalink
OK, I'm still having some issues with this. Here's what I ended up with in
my migrations:

<<
create_table(:books) do
primary_key :id
String :title
end

create_table(:locations) do
primary_key :id
String :location
end

create_table(:books_locations) do
primary_key :id
foreign_key :location_id, :locations
foreign_key :book_id, :books
Integer :total
Integer :checked_out
end
and my models:

<<
class Book < Sequel::Model
one_to_many :book_locations
many_to_many :locations, :join_table=>:book_locations
end

class Location < Sequel::Model
one_to_many :book_locations
many_to_many :books, :join_table=>:book_locations

# Create a class method to grab the id, and locations from the default
# Location dataset.
def self.all_locations
select(:id, :location).all
end

def purchase(book, copies=1)
bl = book_locations(book)
bl ?
bl.update(:copies=>bl.total+copies) :
BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
end
end

class BookLocation < Sequel::Model(:books_locations)
many_to_one :books
many_to_one :locations
end
and here's some test code I wrote:

b = Book.create(:title => 'Snow Crash')
l = Location.create(:location => 'Irvine')
bl = BookLocation.create(:book=>b, :location=>l, :total=>1, :checked_out =>
0)

When I try to add the book location (similar to the purchase() method
above), I get an error:

Sequel::Error: method book= doesn't exist or access is restricted to it.

Thanks again for the help.

Scott
Post by Scott LaBounty
Jeremy,
Thanks I'll mull that over and see what I can do with it. I appreciate all
the help.
Scott
Post by Jeremy Evans
Post by Scott LaBounty
OK, I'm getting confused with the foo, bar, baz thing. I'm trying to do
something very similar (in fact I was going to ask before I saw this
thread). I have a library app. with books and locations. Each book can
have
Post by Scott LaBounty
many locations and each location can have many books. What I'm trying to
add
Post by Scott LaBounty
is a "total" and a "checked_out" value for each book at each location.
Based
Post by Scott LaBounty
create_table(:books) do
primary_key :id
String :title
end
create_table(:locations) do
primary_key :id
String :location
end
create_table(:books_locations) do
primary_key :id
foreign_key :location_id, :locations
foreign_key :book_id, :books
Integer :total
Integer :checked_out
end
class Book < Sequel::Model
one_to_many :book_locations
many_to_many :locations, :join_table=>:book_locations
Post by Scott LaBounty
end
class Location < Sequel::Model
one_to_many :book_locations
many_to_many :books, :join_table=>:book_locations
Post by Scott LaBounty
end
class BookLocation < Sequel::Model
many_to_one :book
many_to_one :location
Post by Scott LaBounty
end
The BookLocations is what I gather from Jeremy's post that I need
(should
Post by Scott LaBounty
those lines be "many_to_many" though?
Now though, I'm not sure what I need to add to the Book model to let me
add
Post by Scott LaBounty
count and checked_out values (and change them) for a given destination.
Thoughts?
The association modification methods are fairly generic, for domain
specific behavior like you probably need, you probably should write
class Location
def purchase(book, copies=1)
bl = book_location(book)
bl ? bl.update(:copies=>bl.copies+copies) : BookLocation.create
(:book=>book, :location=>self, :total=>copies, :checked_out=>0)
end
def sold(book, copies=1)
bl = book_location(book)
bl.update(:copies=>bl.copies-copies)
end
def checkout(book)
bl = book_location(book)
bl.update(:checked_out=>bl.copies+1)
end
def checkin(book)
bl = book_location(book)
bl.update(:checked_out=>bl.copies-1)
end
def book_location(book)
book_locations_dataset[:book_id=>book.id]
end
end
That's just a guess based on the probable needs of your app.
Jeremy
--
Scott
http://steamcode.blogspot.com/
--
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To post to this group, send email to sequel-talk-/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jeremy Evans
2009-07-14 16:00:29 UTC
Permalink
Post by Scott LaBounty
OK, I'm still having some issues with this. Here's what I ended up with in
<<
        create_table(:books) do
            primary_key :id
            String :title
        end
        create_table(:locations) do
            primary_key :id
            String :location
        end
First, make sure you use the same join table name:

        create_table(:book_locations) do
Post by Scott LaBounty
            primary_key :id
            foreign_key :location_id, :locations
            foreign_key :book_id, :books
            Integer :total
            Integer :checked_out
        end
<<
class Book < Sequel::Model
    one_to_many :book_locations
    many_to_many :locations, :join_table=>:book_locations
end
class Location < Sequel::Model
    one_to_many :book_locations
    many_to_many :books, :join_table=>:book_locations
    # Create a class method to grab the id, and locations from the default
    # Location dataset.
    def self.all_locations
        select(:id, :location).all
    end
    def purchase(book, copies=1)
I'm not sure this will work as you think. book_locations will return
an array of BookLocations, not a single one for the book. You
probably want the book_location method I used earlier.
Post by Scott LaBounty
        bl = book_locations(book)
        bl ?
            BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
    end
end
many_to_one takes a singular, not a plural:

class BookLocation < Sequel::Model(:book_locations)
    many_to_one :book
    many_to_one :location
Post by Scott LaBounty
end
b = Book.create(:title => 'Snow Crash')
l = Location.create(:location => 'Irvine')
bl = BookLocation.create(:book=>b, :location=>l, :total=>1, :checked_out =>
0)
When I try to add the book location (similar to the purchase() method
Sequel::Error: method book= doesn't exist or access is restricted to it.
Fixing the many_to_one to be singular should solve this.

Jeremy
Scott LaBounty
2009-07-14 16:21:12 UTC
Permalink
Jeremy,

Thanks, it made it through my test at least. I'll give the real code a try
next. I can't tell you how much I appreciate the help I receive on this
list.

Scott
Post by Jeremy Evans
Post by Scott LaBounty
OK, I'm still having some issues with this. Here's what I ended up with
in
Post by Scott LaBounty
<<
create_table(:books) do
primary_key :id
String :title
end
create_table(:locations) do
primary_key :id
String :location
end
create_table(:book_locations) do
Post by Scott LaBounty
primary_key :id
foreign_key :location_id, :locations
foreign_key :book_id, :books
Integer :total
Integer :checked_out
end
<<
class Book < Sequel::Model
one_to_many :book_locations
many_to_many :locations, :join_table=>:book_locations
end
class Location < Sequel::Model
one_to_many :book_locations
many_to_many :books, :join_table=>:book_locations
# Create a class method to grab the id, and locations from the
default
Post by Scott LaBounty
# Location dataset.
def self.all_locations
select(:id, :location).all
end
def purchase(book, copies=1)
I'm not sure this will work as you think. book_locations will return
an array of BookLocations, not a single one for the book. You
probably want the book_location method I used earlier.
Post by Scott LaBounty
bl = book_locations(book)
bl ?
BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
end
end
class BookLocation < Sequel::Model(:book_locations)
many_to_one :book
many_to_one :location
Post by Scott LaBounty
end
b = Book.create(:title => 'Snow Crash')
l = Location.create(:location => 'Irvine')
bl = BookLocation.create(:book=>b, :location=>l, :total=>1, :checked_out
=>
Post by Scott LaBounty
0)
When I try to add the book location (similar to the purchase() method
Sequel::Error: method book= doesn't exist or access is restricted to it.
Fixing the many_to_one to be singular should solve this.
Jeremy
--
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To post to this group, send email to sequel-talk-/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Scott LaBounty
2009-07-14 19:55:16 UTC
Permalink
OK, I fell like we're getting towards the end here (I'm guessing you're
hoping we are).

In the purchase method:

<<
def purchase(book, copies=1)
bl = book_location(book)
bl ?
bl.update(:copies=>bl.total+copies) :
BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
end
the bl = book_location(book) line says that book_location is undefined, but
if I use
bl = book_locations(book), it works, but as you noted, I do get back an
array. Should the book_location() work?

Also, I'm a little unclear of the singular / plural. In my tables, I create
the book/location join table as book_locations. It looks like that then
flowed through the models. Should I have made that books_locations with them
both plural and then used that in the models?

Once again, thanks for your patience.

Scott
Post by Scott LaBounty
Jeremy,
Thanks, it made it through my test at least. I'll give the real code a try
next. I can't tell you how much I appreciate the help I receive on this
list.
Scott
Post by Jeremy Evans
Post by Scott LaBounty
OK, I'm still having some issues with this. Here's what I ended up with
in
Post by Scott LaBounty
<<
create_table(:books) do
primary_key :id
String :title
end
create_table(:locations) do
primary_key :id
String :location
end
create_table(:book_locations) do
Post by Scott LaBounty
primary_key :id
foreign_key :location_id, :locations
foreign_key :book_id, :books
Integer :total
Integer :checked_out
end
<<
class Book < Sequel::Model
one_to_many :book_locations
many_to_many :locations, :join_table=>:book_locations
end
class Location < Sequel::Model
one_to_many :book_locations
many_to_many :books, :join_table=>:book_locations
# Create a class method to grab the id, and locations from the
default
Post by Scott LaBounty
# Location dataset.
def self.all_locations
select(:id, :location).all
end
def purchase(book, copies=1)
I'm not sure this will work as you think. book_locations will return
an array of BookLocations, not a single one for the book. You
probably want the book_location method I used earlier.
Post by Scott LaBounty
bl = book_locations(book)
bl ?
BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
end
end
class BookLocation < Sequel::Model(:book_locations)
many_to_one :book
many_to_one :location
Post by Scott LaBounty
end
b = Book.create(:title => 'Snow Crash')
l = Location.create(:location => 'Irvine')
bl = BookLocation.create(:book=>b, :location=>l, :total=>1, :checked_out
=>
Post by Scott LaBounty
0)
When I try to add the book location (similar to the purchase() method
Sequel::Error: method book= doesn't exist or access is restricted to it.
Fixing the many_to_one to be singular should solve this.
Jeremy
--
Scott
http://steamcode.blogspot.com/
--
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To post to this group, send email to sequel-talk-/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jeremy Evans
2009-07-14 20:51:15 UTC
Permalink
Post by Scott LaBounty
OK, I fell like we're getting towards the end here (I'm guessing you're
hoping we are).
<<
    def purchase(book, copies=1)
        bl = book_location(book)
        bl ?
            BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
    end
the bl = book_location(book) line says that book_location is undefined, but
if I use
bl = book_locations(book), it works, but as you noted, I do get back an
array. Should the book_location() work?
If you add the book_location method I defined in a previous message,
then yes it will. Otherwise, no, the method will not be defined.
Here it is again:

def book_location(book)
book_locations_dataset[:book_id=>book.id]
end
Post by Scott LaBounty
Also, I'm a little unclear of the singular / plural. In my tables, I create
the book/location join table as book_locations. It looks like that then
flowed through the models. Should I have made that books_locations with them
both plural and then used that in the models?
You can use either naming convention as long as you are consistent.
If you use book_locations, you need to specify the :join_table
argument in your many_to_manys. If you use books_locations, you'll
have to specify the dataset for the BookLocation model.
book_locations seems like the best table name to me, though.

Jeremy
Scott LaBounty
2009-07-14 21:04:57 UTC
Permalink
Jeremy,

Sorry, I totally missed that new method.

Thanks for the explanation of the singular / plural etc.

Scott
Post by Jeremy Evans
Post by Scott LaBounty
OK, I fell like we're getting towards the end here (I'm guessing you're
hoping we are).
<<
def purchase(book, copies=1)
bl = book_location(book)
bl ?
BookLocation.create(:book=>book, :location=>self,
:total=>copies, :checked_out=>0)
end
the bl = book_location(book) line says that book_location is undefined,
but
Post by Scott LaBounty
if I use
bl = book_locations(book), it works, but as you noted, I do get back an
array. Should the book_location() work?
If you add the book_location method I defined in a previous message,
then yes it will. Otherwise, no, the method will not be defined.
def book_location(book)
book_locations_dataset[:book_id=>book.id]
end
Post by Scott LaBounty
Also, I'm a little unclear of the singular / plural. In my tables, I
create
Post by Scott LaBounty
the book/location join table as book_locations. It looks like that then
flowed through the models. Should I have made that books_locations with
them
Post by Scott LaBounty
both plural and then used that in the models?
You can use either naming convention as long as you are consistent.
If you use book_locations, you need to specify the :join_table
argument in your many_to_manys. If you use books_locations, you'll
have to specify the dataset for the BookLocation model.
book_locations seems like the best table name to me, though.
Jeremy
--
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To post to this group, send email to sequel-talk-/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Clive Crous
2009-07-16 08:30:34 UTC
Permalink
Post by Jeremy Evans
One way to do what you want is to have the add_*/remove_*/remove_all_*
methods take additional arguments, and pass those arguments down to
 class Foo
   def _add_bar(bar, values={})
     DB[:foos_bars].insert(values.merge
(:foo_id=>id, :bar_id=>bar.id))
   end
 end
I'm not opposed to a patch that does that, assuming it came with
decent specs.
Hi Jeremy,

I've made an attempt at implementing your suggestion and have sent you
a pull request on github as well. The patch in question is this one:

http://github.com/clivecrous/sequel/commit/cb90ac5d9bb13aaffd51735df93ce9184fc761d9

Thanks,
Clive
Jeremy Evans
2009-07-17 13:52:36 UTC
Permalink
Post by Clive Crous
I've made an attempt at implementing your suggestion and have sent you
http://github.com/clivecrous/sequel/commit/cb90ac5d9bb13aaffd51735df9...
The patch looks good, I should be able to apply it when I get back
from Tokyo.

Jeremy

Continue reading on narkive:
Loading...