SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Many to Many not Updating

    Hi I have the following tables

    version
    id
    name

    delivery_methods_versions

    version_id
    delivery_method_id
    notes

    delivery_methods

    id,
    name


    For some reason I can't save or alter the "notes" field in the "delivery_methods_versions" table.

    Code:
     # At this point I have a reference to the "middle table" object
     @delivery_method = version.find_delivery_method_by_name("Download")
     
     @delivery_method.notes = "yay"
     @delivery_method.save
    Now when I check the database, the row has not been updated. Any help would be appreciated.

  2. #2
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, it looks like with Rails 1.0, join tables being managed with the has_and_belongs_to_many aren't good at managing extra attributes. I guess the solution is to create something like

    delivery_methods_versions
    id,
    version_id
    delivery_method_id
    notes

    then manage the join yourself without all the rails "magic"

    It also appears that the next release of rails will have something called a "join model"

    in the "Versions" model you would define something like:

    Code:
      class Versions < ActiveRecord::Base
        has_many :delivery_methods_versions
        has_many :delivery_methods, through => ::delivery_methods_versions
      
      end


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •