Help me with this Custom Type

7 views
Skip to first unread message

Sean Bollin

unread,
Nov 21, 2013, 2:19:56 AM11/21/13
to mongo...@googlegroups.com
I'm stuck on trying to create this custom type.

Here's what I need:

The data stored in the database is a simple abbreviated string direction: 'n' or 'e' or 'se'

When you retrieve the Direction class from the database you can access a member variable in abbreviated form ('e' or 's') or long form ('east' or 'south')

For example: Direction.new('n') stores in the database as 'n', but when you access it you can do direction.abbrev is equal to 'n' or direction.long is equal to 'north'

Here's what does not work: https://gist.github.com/seanbollin/7577272

Do you typically create a custom type with Direction.new('n') or more usually with direction: 'n'?

When I create a new Direction.new('n') the to_mongo method is called multiple times.  Any idea why?  Thanks.


Jason

unread,
Nov 21, 2013, 10:11:14 AM11/21/13
to mongo...@googlegroups.com
Hi Sean,

I made a comment on your gist with an alternative approach that hopefully understands your goal. I’m also open to feedback on the alternative!

Cheers,
Jason
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "MongoMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongomapper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages