Hi guys - Is it possible to have an attribute be an array of Ruby objects (instead of a String/Integer)? I don't need indexes on those attributes, but just need the ability to do store them, so that I don't have to do JOINs while querying for associations. Is this achieved by defining my own converter (Friendly::Attributes::CONVERTER)? Is there a best practice for this? Thanks in advance! Cheers, Arun -- It's better to be a pirate than join the Navy - Steve Jobs http://mclov.in
Hey Arun, What I ended up doing was convert to a json store before placing inside the attribute for converted access through getter/setter. Seems to have worked out well for me. Thanks On Tue, Feb 2, 2010 at 4:55 AM, Arun Thampi <arun.thampi@gmail.com> wrote: > Hi guys - Is it possible to have an attribute be an array of Ruby objects > (instead of a String/Integer)? I don't need indexes on those attributes, but > just need the ability to do store them, so that I don't have to do JOINs > while querying for associations. Is this achieved by defining my own > converter (Friendly::Attributes::CONVERTER)? Is there a best practice for > this? > Thanks in advance! > Cheers, > Arun > > -- > It's better to be a pirate than join the Navy - Steve Jobs > http://mclov.in > -- Newman Scott Hunter scott@driftlogic.net / c: 613-252-4552
Hi Arun, You can add serialization methods for custom types with Friendly::Attribute.register_type. There aren't any docs yet, but have a look at the code - it's fairly simple, and there is an example of usage in lib/friendly/uuid.rb. Let me know if you have any questions. - James On Tue, Feb 2, 2010 at 9:00 AM, Newman Hunter <scott@driftlogic.net> wrote: > Hey Arun, > > What I ended up doing was convert to a json store before placing > inside the attribute for converted access through getter/setter. Seems > to have worked out well for me. > > Thanks > > On Tue, Feb 2, 2010 at 4:55 AM, Arun Thampi <arun.thampi@gmail.com> wrote: > > Hi guys - Is it possible to have an attribute be an array of Ruby objects > > (instead of a String/Integer)? I don't need indexes on those attributes, > but > > just need the ability to do store them, so that I don't have to do JOINs > > while querying for associations. Is this achieved by defining my own > > converter (Friendly::Attributes::CONVERTER)? Is there a best practice > for > > this? > > Thanks in advance! > > Cheers, > > Arun > > > > -- > > It's better to be a pirate than join the Navy - Steve Jobs > > http://mclov.in > > > > > > -- > Newman Scott Hunter > scott@driftlogic.net / c: 613-252-4552 >
Thanks Newman and James. I've got it working using Newman's approach and it works fine. However with this approach, do we run the risk of exceeding the 'text' limits of MySQL? In my test case, there were certain documents which exceeded this limit and thus when I tried to retrieve it, the JSON-parsing would fail and the document could not be received. Would changing the default type of the 'attributes' column to mediumtext instead of text be feasible? Thanks again for your help. Cheers, Arun On Wed, Feb 3, 2010 at 1:50 AM, James Golick <jamesgolick@gmail.com> wrote: > Hi Arun, > > You can add serialization methods for custom types with > Friendly::Attribute.register_type. There aren't any docs yet, but have a > look at the code - it's fairly simple, and there is an example of usage in > lib/friendly/uuid.rb. > > Let me know if you have any questions. > > - James > > > On Tue, Feb 2, 2010 at 9:00 AM, Newman Hunter <scott@driftlogic.net>wrote: > >> Hey Arun, >> >> What I ended up doing was convert to a json store before placing >> inside the attribute for converted access through getter/setter. Seems >> to have worked out well for me. >> >> Thanks >> >> On Tue, Feb 2, 2010 at 4:55 AM, Arun Thampi <arun.thampi@gmail.com> >> wrote: >> > Hi guys - Is it possible to have an attribute be an array of Ruby >> objects >> > (instead of a String/Integer)? I don't need indexes on those attributes, >> but >> > just need the ability to do store them, so that I don't have to do JOINs >> > while querying for associations. Is this achieved by defining my own >> > converter (Friendly::Attributes::CONVERTER)? Is there a best practice >> for >> > this? >> > Thanks in advance! >> > Cheers, >> > Arun >> > >> > -- >> > It's better to be a pirate than join the Navy - Steve Jobs >> > http://mclov.in >> > >> >> >> >> -- >> Newman Scott Hunter >> scott@driftlogic.net / c: 613-252-4552 >> > > -- It's better to be a pirate than join the Navy - Steve Jobs http://mclov.in