#835 ✓resolved
Tomoaki Hayasaka

scoped collection doesn't return correct origin and origin_attribute

Reported by Tomoaki Hayasaka | October 25th, 2010 @ 12:16 PM | in Hobo 1.3 (Rails 3)

See:

irb(main):001:0> User.first.tweets.recent.origin # should return first user
=> nil
irb(main):013:0> User.first.tweets.recent.origin_attribute # should == :tweets
=> nil

Because of this, <aside> in <show-page> causes ActionView::Template::Error (The context is not an ActiveRecord::Base instance or class. (this = nil)).

Test:

class User < ActiveRecord::Base
  hobo_user_model # Don't put anything above this
  fields do
    name          :string, :required, :unique
    email_address :email_address, :login => true
    administrator :boolean, :default => false
    timestamps
  end
  has_many :tweets
  def create_permitted?; true; end
  def update_permitted?; true; end
  def destroy_permitted?; true; end
  def view_permitted?(field); true; end
end

class Tweet < ActiveRecord::Base
  hobo_model # Don't put anything above this
  fields do
    tweet :string
    timestamps
  end
  belongs_to :user
  def create_permitted?; true; end
  def update_permitted?; true; end
  def destroy_permitted?; true; end
  def view_permitted?(field); true; end
end

class TweetsController < ApplicationController
  hobo_model_controller
  auto_actions :all
  auto_actions_for :user, [:index, :new, :create]
end

class UserHints < Hobo::ViewHints
  children :tweets, :tweets
end

and visit /users.

Or for scopes.rdoctest:

    >> Bryan.friends.origin.name
    => "Bryan"
    >> Bryan.friends.order(:id).origin.name
    => "Bryan"
    >> Bryan.friends.order_by(:id).origin.name
    => "Bryan"

    >> Bryan.friends.origin_attribute
    => :friends
    >> Bryan.friends.order(:id).origin_attribute
    => :friends
    >> Bryan.friends.order_by(:id).origin_attribute
    => :friends

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Tags

Referenced by

Pages