Arc Forumnew | comments | leaders | submitlogin
One-to-many, many-to-many, etc
2 points by wfarr 6080 days ago | 6 comments
I've basically hit a cross-roads in my blog development with Arc such that I either need to find a way to make the above mappings work with the current hash-driven setup, or stop adding features (that I happen to want).

I haven't gotten much of anywhere on it, but I'm more interested in what ideas you guys might have on what would be a nice, Lispy way to approach the problem. These type of things benefit everyone, so working together's always a good plan. =)



2 points by skenney26 6079 days ago | link

What does your current database look like? What relationships are you hoping to add?

I assume you're using deftem to define your database objects. I was thinking that it would helpful to have a version of deftem that automatically created defops for adding, updating, and deleting objects from a database (similar to Rails scaffolding).

-----

1 point by wfarr 6079 days ago | link

I know someone made scaffolding work earlier, but I don't know exactly how they did it.

Anyway, ideally with templates -- in my case, one for posts and one for tags -- you'd be able to make use of this relation in a functional way with no real performance issues.

-----

3 points by drcode 6079 days ago | link

I was the one who created the scaffolding system- It does, indeed, generate the code to add/update/etc from a database. I've continued to expand the system on my own, but since there wasn't much interest in the arc forum I decided not to continue checking code into anarki for now, but may again in the future- So right now it is strictly ver 0.01, though I'm surprised others seem to manage without a scaffolding system...

As for the issue of one-many and many-many, I guess I would suggest that in a one-to-many situation I would try and store the "many" as a child field in the "one", not use two separate tables if you can get away with it (one of the advantages of a non-RDBMS is that this design is possible)

As for many-many, I would probably have two tables, then have an extra table that just maps keys to keys for the two tables. Basically, just like an RDBMS association table. (or maybe even a bidirectional table, if you need to go "both ways")

If you want to know the "official" way to store data in different relationships in a simple, purely functional, memory resident database, I'd look at HApps-ixset. This is philisophically closely aligned to what you'd need in arc and is designed by some super smart guys. Unfortunately, their documentation is wanting or I'd point you to a good link that describes how to use it.

Those are some thoughts.

-----

2 points by skenney26 6078 days ago | link

I've been thinking it might be possible to make these mappings implicit. Imagine you had a version of deftem (I'll call it defitem) that inspected the fields in your templates:

  (defitem post
    id     nil
    title  nil
    text   nil
    tags   nil)

  (defitem tag
    id     nil
    text   nil
    post   nil)
defitem would see that post has a relationship with tag and tag has a relationship with post by looking at the names of the fields in each template. Since the post field in tag is singular and the tags field in post in plural, it would know that there is a one-to-many relationship between post and tag. Then defitem could create any necessary accessor methods.

Anyways, that's what I've been attempting recently.

-----

2 points by rincewind 6079 days ago | link

Do you want to integrate an Object-Relational-Mapper with the existing web scaffolding, or a complete MVC framework?

-----

1 point by wfarr 6078 days ago | link

The former, ideally.

-----