I'm struggling a little bit with a chicken and egg problem with Sequel
Models. I'm building an online content management system, which is
basically a website comprised of pages. For SEO purposes, I am
designing my CMS so that pages get resolved by their title. For
example:
Page Title, "Michael's Awesome Home Page" gets slugged so that:
http://www.sample.com/michaels-awesome-home-page
finds the page.
Normally, I would just store the slugged title as a field in the pages
table. However, I want the ability to have more than one slug for a
page. Two reasons:
1) to preserve old URLs in the case of a migrated site.
2) The page can be found by old title when title of the page
changes.
In both cases, I want preserve those URLs because other sites and
search engines may have spidered the site or bookmarked the old slug
and still send traffic to the old URL's...so...if my Awesome Home page
used to exist as: http://www.sample.com/index.html, I will want an
entry in my slugs table for that as well as the new SEO optimized
slug.
So, here's the Chicken and Egg problem:
I am trying to assign the generated slug for the page to a
pages::slug_id column so that I have quick, direct access to the slug
that is the one to be used to generate URLs in the CMS when rendering
links to the page.
I cannot associate a slug to a page until after the page has been
saved and an ID for the page is known. Thus, I cannot associate the
slug to the page in the before_save, after_create, or after_initialize
callbacks.
If I try to associate the slug to the page in the page's after_save
callback, then the slug_id for the page doesn't get populated with the
slug record's id.
This is my two models:
class Page < Sequel::Model
many_to_one :slug
end
class Slug < Sequel::Model
many_to_one :page
end
Ideally, I would like to do something like the following:
new_page = Page.new(:name => "Michael's Awesome Home Page")
new_page.add_slug("index.html)
new_page.save
and have:
Page.first ==>
:id => 1
:name => "Michael's Awesome Home Page"
:slug_id => 1
Slug.first ==>
:id => 1
:page_id => 1
:name => 'michaels-awesome-home-page'
Slug.last ==>
:id => 2
:page_id => 1
:name => 'index.html'
Michael
--
http://ramblings.gibberishcode.net
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.