>
> I have created class using `Active Model`,it is working as expected ,but
> am having few requirements
>
> 1) I want to use `all` method for that `class`.
>
> 2) Same way i want to use some query methods like `where` method for that
> `class`.
>
> 3) I want to create `ActiveRecord::Relation` so that i can do method
> chaining.
>
>
> See my class:
>
> require 'active_model'
> require 'active_record'
>
>
> class Message
> include ActiveModel::Validations
> include ActiveModel::Conversion
> extend ActiveModel::Naming
>
> attr_accessor :name, :email, :content
>
> validates_presence_of :name
> validates_length_of :content, :maximum => 500
>
> def initialize(attributes = {})
> attributes.each do |name, value|
> send("#{name}=", value)
> end
> end
>
> def persisted?
> false
> end
> end
>
>
> m = Message.new(:email => "test",:name => "test")
> puts m.name #=> test
> puts m.class #=> Message
> puts m.valid? #=> true
>
> Message.all
> Message.where(:name => "test")
>
> some more methods:
>
> where
> limit
> having
> group
> select
> order
> uniq
>
> Could you please help me to achieve this or give some guide lines.
>
For more details see link: active-record-query-methods-for-simple-class
<http://stackoverflow.com/questions/28276451/active-record-query-methods-for-simple-class>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/92128b7b-be42-491f-a87e-73fd854df3e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.