Best way to dump one database table with limit and all association

dump, mysql, ruby-on-rails, yaml

Solution

Take first 5000 records:

mysqldump --opt --where="1 limit 5000" -uroot development profiles  > profiles.sql 

Then find all associated with this records friends:

mysqldump --opt --lock-all-tables --where="profile_id IN (SELECT * FROM (SELECT id FROM profiles LIMIT 5000) temp);" -uroot development friends  > friends.sql

Problem

``` class Profile < ActiveRecord::Base has_many :favorites, :dependent => :destroy has_many :friends, :dependent => :destroy end ``` I need smth like this: ``` mysqldump --opt --where="1 limit 1000" -uroot development profiles > profiles.sql ``` But this dump contains (as expected) only 1000 profiles rows, without associations friends, favorites. Should I do it using YAML or how should I do it?

Original source