Skip to content
aaronbee edited this page Sep 14, 2010 · 8 revisions

The basics are the following:
Suppose we have a User entity with a field name.
u = User.new creates a new user.
u.name gets the name attribute.
u.put("name", "Alice") sets the name attribute to “Alice”.
u.name = "Alice" does the same as above as long as you have the following line in your User model:
include PIQLEntity

u.save saves the user to the database.

There is also an alternate constructor that takes in a hash that maps attribute names to values. This makes it possible to do the following in the create controller method:
User.new(params[:user]).
In this case the passed in hash would like something like {"name" => "Bob", "password" => "12345"}.

Rails Models

  • The models directory of your Rails app should have files that are the lowercased name of each Entity that you want to add functionality to.
  • This file should include a class definition with a name matching the Entity. The class should not inherit from anything.
  • The class should mix-in (ie. include) PIQLEntity

For example, the Entity user would have a file app/models/user.rb that looks like the following:

class User
  include PIQLEntity
  # Other code
end
Clone this wiki locally