yaml_record icon indicating copy to clipboard operation
yaml_record copied to clipboard

Add associations

Open nesquena opened this issue 13 years ago • 2 comments

We should add association support:

class Post < YamlRecord::Base
   belongs_to :episode
   # auto-adds `property :episode_id, Integer`
end

This adds a episode_id integer foreign key reference. You can then do stuff like:

p = Post.new
p.episode = Episode.find(5)
p.save
p.episode # => <Episode id=5>
p.episode_id # => 5

or:

p = Post.new
p.episode_id = 5
p.save
p.episode # => <Episode id=5>
p.episode_id # => 5

Also adds embeds_many support:

class Post < YamlRecord::Base
  embeds_many :users
  # adds property :user_ids, Array, Integer
end

and allows for:

p = Post.new
p.user_ids = "1,2,3"
p.save
p.users # => [<User 1>, <User 2>, <User 3>]

nesquena avatar Feb 01 '12 08:02 nesquena

:yellow_heart:

robertomiranda avatar Feb 23 '15 21:02 robertomiranda

@robertomiranda Appreciate any help with this. Code base is pretty simple. Nico and I have unfortunately somewhat abandoned this project (I still use it though).

nesquena avatar Feb 23 '15 22:02 nesquena