On Tue, Jul 11, 2017 at 6:33 AM, Ralph Shnelvar <
ral...@dos32.com> wrote:
> I want to make sure the first user gets to set it's role attribute to enum
> :admin as the default when the record is created and all other users are
> enum :user.
>
> Of course a billion users is ridiculous. I'm just trying to understand what
> the, uh, best way to see if a Postgres table is empty without actually
> having to load it.
Assuming the table is "users" and User is an ActiveRecord model,
(User.count == 0)
should work.
However, doing that for every subsequent user creation seems like
a bit of a waste. I would just use the db/seeds.rb file to create that
first admin user and be done with it :-)
FWIW,
--
Hassan Schroeder ------------------------
hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote