It seems to me that if you used <sortable-collection> on a set of
alteration_assignments rather than on a set of alterations, it should
work.   Are you using Hobo 2.0 or 1.3?

Bryan


On Wed, Dec 12, 2012 at 2:45 PM, Ryan <[email protected]> wrote:
> I have a many-to-many where the order matters on one side, and the draggable
> reordering that the Agility tutorial uses would be great to use - however it
> doesn't seem to be as easy as the one-to-many example in the tutorial.
>
> I have my objects and relationships set up as:
>
> class Destination < ActiveRecord::Base
>
>   hobo_model # Don't put anything above this
>
>   fields do
>     name                       :string
>     timestamps
>   end
>   attr_accessible :name, :alterations
>
>   has_many :alteration_assignments, :dependent => :destroy
>   has_many :alterations, :through => :alteration_assignments, :accessible =>
> true, :dependent => :destroy, :order => "position"
>
>   children :alterations
>
>
> class Alteration < ActiveRecord::Base
>
>   hobo_model # Don't put anything above this
>
>   fields do
>     name   :string
>     script :string
>     timestamps
>   end
>   attr_accessible :name, :script
>
> has_many :alteration_assignments, :dependent => :destroy
> has_many :destinations, :through => :alteration_assignments
>
>
> class AlterationAssignment < ActiveRecord::Base
>
>   hobo_model # Don't put anything above this
>
>   fields do
>     timestamps
>   end
>   attr_accessible
> belongs_to :destination
> belongs_to :alteration
> acts_as_list :scope => :destination
>
>
> It works great - alterations are added, and the position field is set
> properly when adding an alteration, except the draggable list doesn't render
> - the normal alteration cards show up under show destination, and the normal
> alteration select/add/remove shows up under edit destination.
>
> I'm assuming the problem has to do with the acts_as_list only being on the
> assignment object and not the actual alteration object:
>
> irb(main):004:0> destination.alterations.first.move_to_bottom
>   Alteration Load (19.1ms)  SELECT "alterations".* FROM "alterations" INNER
> JOIN "alteration_assignments" ON "alterations"."id" =
> "alteration_assignments"."alteration_id" WHERE
> "alteration_assignments"."destination_id" = 4 ORDER BY position LIMIT 1
> NoMethodError: undefined method `move_to_bottom' for #<Alteration:0xaa229e8>
>
>
> irb(main):006:0> destination.alteration_assignments.first.move_to_bottom
>   AlterationAssignment Load (1.0ms)  SELECT "alteration_assignments".* FROM
> "alteration_assignments" WHERE "alteration_assignments"."destination_id" = 4
> LIMIT 1
>    (0.6ms)  BEGIN
>   SQL (0.9ms)  UPDATE "alteration_assignments" SET position = (position - 1)
> WHERE ("alteration_assignments"."destination_id" = 4 AND position > 1)
>   AlterationAssignment Load (1.1ms)  SELECT "alteration_assignments".* FROM
> "alteration_assignments" WHERE ("alteration_assignments"."destination_id" =
> 4 AND id != 4) ORDER BY alteration_assignments.position DESC LIMIT 1
>    (0.8ms)  UPDATE "alteration_assignments" SET "position" = 2, "updated_at"
> = '2012-12-12 19:36:58.007222' WHERE "alteration_assignments"."id" = 4
>    (0.9ms)  SELECT COUNT(*) FROM "alteration_assignments" WHERE
> ("alteration_assignments"."destination_id" = 4 AND position = 2)
>    (55.0ms)  COMMIT
> => true
>
>
> Is there a way to get Hobo to deal with this automagically like with
> one-to-many, or do I need to write something myself?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/rBbimvP3HzcJ.
> 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/hobousers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en.

Reply via email to