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

Association improvements #307

Merged

Conversation

Blacksmoke16
Copy link
Contributor

  • Allows custom primary keys on belongs_to and has_one associations.
  • Adds bang, raise on nil, methods to belongs_to and has_one associations.
  • Makes the has_many association use whatever primary key is defined on the model, vs always assuming id

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Much needed feature! thx.

primary courier_id : Int32, auto: false
field! issuer_id : Int32

belongs_to service : CourierService, primary_key: "owner_id"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Blacksmoke16 just to confirm, can you use a Symbol instead of a String for the value?

belongs_to service : CourierService, primary_key: :owner_id

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like mysql is failing. :-(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, ill take a look.

Should be able to, just sets it and calls .id on them.

Copy link
Contributor Author

@Blacksmoke16 Blacksmoke16 Nov 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drujensen I figured it out, see 2e80d10.

I guess no other spec had it setup like I did this one time. 🤷‍♂️

EDIT: And yea, symbol primary_key: values works 👌

@drujensen drujensen merged commit a4b3d51 into amberframework:master Nov 25, 2018
@Blacksmoke16 Blacksmoke16 deleted the association-improvements branch November 25, 2018 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants