0.0
No commit activity in last 3 years
No release in over 3 years
Flexible Model
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

 Project Readme

flexi-model

Code Climate

Build flexible database model with dynamic fields (right now based on ActiveRecord soon it will work with mongoid too)

How to do ?

Define your first model.

class User
  include FlexiModel
  _string :name, :email
  _text :bio
  validates_presence_of :name, :email
end

Create your new record.

User.create name: 'hasan', email: 'hasan@welltreat.us', bio: 'Ruby developer'
#=> #<User:...>

Find record by id.

User.find(1)

Find records by name

User.where(name: 'hasan')
#=> #<...::Criteria...> # Instance of criteria object

Define belongs to and has many relationship

class Blog
  include FlexiModel
  _string :title
  _text :content
  belongs_to :user
end

class User
  include FlexiModel
  _string :name
  has_many :blogs
end

# Create records
user = User.create(name: 'nafi')
Blog.create(title: 'Hello world', content: 'Hello content', user: user)

# Find all related blogs
user.blogs

# Find parent record
user.blogs.first.user

Define has and belongs to many relationships

class User
  inlude FlexiModel
  _string :name
  has_and_belongs_to_many :roles
end

class Role
  include FlexiModel
  _string :name
  has_and_belongs_to_many :users
end

# Create user with roles
User.create(name: 'khan', roles: [Role.create(name: 'admin'), Role.create(name: 'moderator')])

# Find user roles
user = User.where(name: 'khan').first
user.roles

Update attribute

user = User.where(...)
user.update_attribute :name, 'raju'

Update attributes

user = User.where(...)
user.update_attributes name: 'raju', email: 'hola@hola.com'

Destroy record

user.destroy
User.where(...conditions...).destroy_all

Observers

  • Before, After and Around Create
  • Before, After and Around Update
  • Before, After and Around Destroy

TODOS

  • Write documentation