Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ver. 4.0.3 to 4.0.4. Then missing attribute: state #193

Closed
kntmrkm opened this issue Dec 6, 2014 · 8 comments
Closed

Ver. 4.0.3 to 4.0.4. Then missing attribute: state #193

kntmrkm opened this issue Dec 6, 2014 · 8 comments
Assignees
Labels

Comments

@kntmrkm
Copy link

kntmrkm commented Dec 6, 2014

I have a question.

My code summary is...

class Reservation < ActiveRecord::Base
  include AASM
  aasm column: :state, skip_validation_on_save: false, requires_new_transaction: false do
      state :issued, initial: true
      state :accepted
      state :refused

When upgrade version 4.0.3 to 4.0.4.
AASM need a column state?

Case 1.

Reservation.select(:date, :period_list_id).find_by(id: params[:reservation_id])

Above code occured this error.

missing attribute: state

So, I added state column.

Reservation.select(:state, :date, :period_list_id).find_by(id: params[:reservation_id])

It's no errors.

Case 2.

   # At controller. 
   @account.reservations.accepted.group_by_date

    # At model.
    scope :group_by_date, -> do
      select(reservations[:date], reservations[:number].sum.as('sum_number')).
      group(:date)
    end

Above code occured error. missing attribute: state.

but, I can't add column state, because Reservation SQL is grouped.

How Should I fix this code?

@alto alto self-assigned this Dec 6, 2014
@alto alto added the bug label Dec 6, 2014
@alto
Copy link
Member

alto commented Dec 6, 2014

I will take a look into this. Just to be clear, it all worked with version 4.0.3?

@kntmrkm
Copy link
Author

kntmrkm commented Dec 6, 2014

Yes.
Version 4.0.3 works well.

@alto
Copy link
Member

alto commented Dec 6, 2014

Allright. Then I know what causes this problem. Will fix it today.

alto added a commit that referenced this issue Dec 6, 2014
…ActiveRecord instance only if the attribute has been loaded #193
alto added a commit that referenced this issue Dec 6, 2014
@alto
Copy link
Member

alto commented Dec 6, 2014

Just released version 4.0.5 fixing this bug. Let me know how things work for you.

@alto alto closed this as completed Dec 6, 2014
@kntmrkm
Copy link
Author

kntmrkm commented Dec 6, 2014

I tried.
It work well.

Thanks for quick fix!

@godfat
Copy link
Contributor

godfat commented Dec 8, 2014

I got this issue in 4.0.4, but this fix in 4.0.5 also breaks something in our application.
I haven't dug into it, and just want to let you know first.
Will stick with 4.0.3 at the moment, and would try to figure out what's going on when I got time on this.

edited: We are running Rails 3 by the way.
edited: First impression is some event hooks didn't run.

@alto
Copy link
Member

alto commented Dec 8, 2014

@godfat Could you create a new ticket, please? And be a little bit more descriptive, what the actual problem is. Cheers!

@godfat
Copy link
Contributor

godfat commented Dec 8, 2014

@alto will do when I got time on digging into it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants