belshnickleson97
belshnickleson97

Reputation: 75

SyntaxError: unexpected ')', expecting end-of-input

This seems like an error you would receive in your early days of coding and for the life of me, I can not figure out why I am receiving this error.

My code is as follows:

Order.joins(:all_adjustments).where(all_adjustments.last: { source_type: "Spree::PromotionAction" } )

Please, any help would be appreciated! I have a feeling I am missing something stupidly obvious...I just can't tell what the heck it is!

ERROR:

SyntaxError: unexpected ')', expecting end-of-input: "Spree::PromotionAction" } )

Thanks in advance

Upvotes: 0

Views: 720

Answers (2)

Sovalina
Sovalina

Reputation: 5609

In the relationship has_many :all_adjustments, class_name: 'Spree::Adjustment', all_adjustments is just a custom name to define the relationship between an order and his adjustments (that's why the class_name is specify)

In the case of your query, you need to joins the association name (so all_adjustments) (source)
With the result of this join, you may create a condition which uses any of the tables in the join.(source). In your case the table name is spree_adjustments.

So your query should work this way:

Spree::Order.joins(:all_adjustments).where(spree_adjustments: { source_type: "Spree::PromotionAction" } )

Upvotes: 1

akowalz
akowalz

Reputation: 369

It's due to where(all_justments.last:, which is invalid syntax.

The argument of where needs to be a hash, and what you have there isn't a valid hash. If you want to use the {key: value} syntax in your hash, key must be a symbol, and you are trying to put an expression there instead.

Try instead

Order.joins(:all_adjustments).where(all_adjustments: { source_type: "Spree::PromotionAction" } )

That may not work depending on how you've set up your relations, but it should get you closer to the real error.

Upvotes: 4

Related Questions