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

Introduce ManyToMany and OneToOneThrough builder #86

Merged
merged 13 commits into from
Jan 19, 2024
Merged

Conversation

solnic
Copy link
Member

@solnic solnic commented Oct 27, 2023

This adds support for building associated structs in case of ManyToMany and OneToOneThrough association types, where intermediate join tables are involved. It works with persistable and in-memory structs.

factories.define(:user) do |f|
  f.first_name { fake(:name, :first_name) }
  f.last_name { fake(:name, :last_name) }
  f.email { fake(:internet, :email) }
  f.timestamps

  f.association :address
end

factories.define(:user_address) do |f|
  f.association(:user)
  f.association(:address)
  f.timestamps
end

factories.define(:address) do |f|
  f.full_address { fake(:address, :full_address) }
end

# Persisted struct
factories[:user]
# #<ROM::Struct::User id=2 last_name="Leuschke" first_name="Don" alias=nil email="[email protected]" created_at=2023-11-24 10:19:25.693242 +0000 updated_at=2023-11-24 10:19:25.693246 +0000 age=nil type=nil address=#<ROM::Struct::Address id=2 full_address="44090 Patrina Vista, Barrowsburgh, SC 87402" user_id=2>>

# In-memory struct works too
factories.structs[:user]
#<ROM::Struct::User id=1 last_name="Zieme" first_name="Mallory" alias=nil email="[email protected]" created_at=2023-11-24 10:20:05.920642677 +0000 updated_at=2023-11-24 10:20:05.920648427 +0000 age=nil type=nil address=#<ROM::Struct::Address id=1 full_address="Suite 376 7225 Ortiz Centers, East Desmondland, MT 16834-2493" user_id=1>>

@solnic solnic force-pushed the support-many-to-many branch 2 times, most recently from 0bd6ed6 to 6fcf8d2 Compare November 24, 2023 10:12
@solnic solnic changed the title Introduce ManyToMany builder Introduce ManyToMany and OneToOneThrough builder Nov 24, 2023
@solnic solnic marked this pull request as draft December 2, 2023 13:58
@solnic
Copy link
Member Author

solnic commented Dec 2, 2023

Switching to Draft again as there are a couple of issues to address

@solnic solnic force-pushed the support-many-to-many branch 4 times, most recently from dd84c97 to 4787e48 Compare December 6, 2023 10:05
@solnic solnic marked this pull request as ready for review December 6, 2023 10:06
@solnic solnic force-pushed the support-many-to-many branch from 4787e48 to 7a72f6e Compare December 8, 2023 08:02
@solnic solnic force-pushed the support-many-to-many branch from 7a72f6e to e5f083a Compare December 15, 2023 16:45
@solnic solnic force-pushed the support-many-to-many branch from e5f083a to c775ce0 Compare January 19, 2024 08:29
@solnic solnic force-pushed the support-many-to-many branch from c775ce0 to 5be2dc2 Compare January 19, 2024 08:30
@solnic solnic merged commit 38440e8 into main Jan 19, 2024
11 checks passed
@solnic solnic deleted the support-many-to-many branch January 19, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants